AWS - ECS - How can I redeploy an updated Docker image on an existing ECS (with 1 EC2) instance?

Viewed 9811

First, I created in AWS a repo with a Docker image in it.

Then I created a Task Definition and an ECS / EC2 cluster. Finally I created a service using the cluster and the Task definition. Works fine.

How can I redeploy an updated Docker image on the existing cluster?

Just 'updating' the service with a new (or existing) task does not work. Even with the 'force new deployment' option has no effect.

2 Answers

If you don't specify the tag of an ECR image on your container definition, it will always fetch the latest one. Thus, you have 2 ways to achieve the re-deployment.

  1. Make sure your service having enough room to deploy a new task, for example, if your desired Number of tasks is 1, then you have to set the Maximum percent to 200, means you can allow 1 * 200% = 2 tasks running at the same time while doing the deployment, then simply type the following command: aws ecs update-service --cluster <cluster name> --service <service name> --force-new-deployment

  2. Or after you update your image to ECR, you can just manually kill the existing task(s) and create a new one (normally the creation process should be done by the ECS itself, as long as your auto scaling configuration is setup correctly).

According to the AWS documentation, you can't really do that... you can read it here - https://docs.aws.amazon.com/cli/latest/reference/ecs/register-task-definition.html

only by "Create new revision of Task Definition" Task definition -> -> create new revision

it will use the "latest" version in your repo (better to tag it with latest of course) or add the tag yourself.

BTW - I would use an automated process for these updates as part of ci/cd with json for that use, unless you already prepare to do so.

Related