Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 288
tm1701 Avatar asked Dec 27 '18 19:12

tm1701


People also ask

Can one ECS task have multiple containers?

You can use an Amazon ECS task definition to specify multiple containers. All the containers that you specify are deployed along the same compute capacity. Don't use this feature to add multiple application containers to the same task definition because this prevents copies of each application scaling separately.


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

like image 108
Rex Lam Avatar answered Oct 17 '22 13:10

Rex Lam


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.

like image 32
oddude Avatar answered Oct 17 '22 13:10

oddude