I'm trying to define my ECS stack in Cloudformation, including the CI/CD pipeline and ECR repository. However you run into a bit of a conundrum in that:
- To create an ECS task definition (
AWS::ECS::TaskDefinition
) you have to first create a populated ECR repository (AWS::ECR::Repository
) so that you can specify theImage
property. - To populate this repository you have to first create the CodePipeline (
AWS::CodePipeline::Pipeline
) which will run automatically on creation. - To create the pipeline you have to first create the ECS task definition / cluster as the pipeline needs to deploy onto it (back to step 1).
The solutions to this I can see are:
- Don't create the ECR repository in Cloudformation & pass it as a parameter to the stacks.
- Define a dummy image in the task definition to deploy the first time and then create the pipeline which will create the real ECR repository and deploy the real image.
- Create the CodeBuild project and ECR repository in a separate stack, trigger the CodeBuild project with a lambda function (I don't think it runs automatically on creation like the pipeline does), create the ECS cluster and then create the pipeline. This seems more complicated than it should be.
Are there any better ways of approaching this problem?