Search code examples
amazon-ecs

Update Docker image in ECS deploy


I deploy on AWS ECS a CloudFormation Stack, say teststack, via the command

aws cloudformation deploy --template-file ./CloudFormationTemplate.yml --stack-name teststack --force-upload

My stack executes a certain Docker image, say myname/myimage:latest.

I want to deploy & update the stack via a pipeline (I'm using GitLab, but I guess this is not relevant for the question of interest here).

In this setting, I may modify my Docker image without touching the CloudFormation Template file; I then build & push the new image myname/myimage:latest to my registry; finally, I trigger a new pipeline, which launches again the command aws cloudformation deploy ... --force-upload.

When executing aws cloudformation deploy ... --force-upload, the pipeline returns No changes to deploy. Stack stack-name is up to date.

Evidently, since the stack is executing the latest tagged images, it returns that everything is up to date, whitout making a pull of the new latest image.

Is there a way to force AWS CloudFormation to pull new Docker images from my registry?


Solution

  • Is using tags other than latest an option here? If so then you could tag the latest change you want to update let say myname/myimage:0-0-1 and then update the container definition in your cloudformation template to use this new tag.

    If you wish to continue using the latest tag you probably cant force the deployment by a cloudformation template update. In my project when I didnt want to change the tag I ended up doing the update using AWS CLI:

    aws ecs update-service --service ${ecsService}  --cluster ${ecsCluster} --region ${region} --force-new-deployment