I want my ECS task definition image tag updated when a newer tag exists.
In CodePipeline after I push the image with new tag, I try to update service with the following command, but it doesn’t get the new image automatically, still the old one.
- docker push ${DOCKERHUB_USER}/aws-dummy-api:${IMAGE_TAG}
- aws ecs update-service --cluster my-cluster --service dummy-api-service --force-new-deployment --region eu-central-1
So how to get the new image tag automatically when I push a new tag?
2
Answers
It seems I need to create a new revison with the new image tag, and update the ECS service.
Following this github issue, I managed like this in my CodePipeline buildspec.yml:
You are missing a step. After the docker push you need to update the task definition (create a new task definition revision) with the new image tag. After that you need to trigger the ECS service to deploy by passing it the
--task-definition
parameter with the new task definition revision ID. And remove the--force-new-deployment
parameter, as that is for deploying new containers with the current task revision, not for deploying an updated task revision.Task definitions in ECS are immutable, so you can’t just update a value on an existing task definition. You have to create an entirely new revision of the task definition. The CLI tool command to do that would be
aws ecs register-task-definition
. To do this purely through the AWS CLI tool for this, this looks like a good tutorial.