tm1701
tm1701

Reputation: 7601

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

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.

Upvotes: 17

Views: 18313

Answers (2)

Rex Lam
Rex Lam

Reputation: 1405

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).

Upvotes: 21

oddude
oddude

Reputation: 31

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.

Upvotes: 2

Related Questions