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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With