Deploying Updated Task Definitions and Docker Images on AWS

DZone 's Guide to

Deploying Updated Task Definitions and Docker Images on AWS

You can quickly update task definitions on AWS and Docker images in your AWS ECS cluster, which helps with scaling your apps.

· Cloud Zone ·
Free Resource

In my previous blog posts on AWS (launching an Amazon ECS cluster and scaling with Amazon ECS), I explained how to deploy a sample app by creating a task definition, scheduling tasks, and configuring a cluster on Amazon ECS and to scale in/scale out the same.

In this, I will guide you through creating a new revision for existing task definitions to use the latest updated Docker image and then to run the service with new Docker image and updated revision.

You can simply update the running service by changing the task definition revision. When a deployment is triggered by updating the task definition of a service, the service scheduler uses the deployment configuration parameters minimumHealthyPercent and maximumPercent to determine the deployment strategy.

If the minimumHealthyPercent is below 100%, the scheduler can ignore the desired count temporarily during a deployment. For example, if your service has a desired count of two tasks, a minimumHealthyPercent of 50% allows the scheduler to stop one existing task before starting a new task. But if the minimumHealthyPercent is 100%, then you need one plus an EC2 instance in your cluster. For example, if your service has a desired count of two tasks then first it will start the third task and stop one existing task. This means by using this deployment strategy, it will automatically run a new task and stop the existing one.

Let's see how can we update a service in order to run the updated version of task definition/Docker images.

a. Running an application: Currently running on the first version of the task definition.


b. Create a new revision of the task definition: Open the Amazon ECS console, and in the navigation pane, choose “Task Definitions.” Then select the existing definition and click on “Create new revision”.


c. Click on “container definition:”


d. Update task definition: Here, I’m updating the command section to change background and font color, and changing the text to ‘Congratulations you have updated version.’ You can also specify the Docker image version in the image section—if you want to go with the latest image, then there's no need to change it, but you always have to create a new revision whenever you want to use the  latest Docker image. As the existing service will keep on running with the old version of the task definition, you'll want previous the version of the Docker image in case you have updated the image on the repository.


e. Task definition revision: Now you can see there are two revisions of the task definition.


f. Update Service: Now in the navigation pane, choose “Clusters.” Then under the service tab, update the running service to the new revision of task definition.


g. Click on the “tasks” tab: In a while, you will see that the new task will start with the new revision of the task definition and the old one will automatically get stopped.  I have already scaled the EC2 instance count to 2 in a cluster, so the above-mentioned deployment strategy can trigger the deployment process.


h. Running updated service:


In the next blog, I will explain how to clean up Amazon ECS resources.

amazon ecs, cloud, docker images, task definition, tutorial

Published at DZone with permission of Prashant Goel , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}