AWS | Amazon ECS — Deploy Updated Task Definition/Docker Images

Knoldus Inc.
Knoldus - Technical Insights
4 min readJan 6, 2017

In my previous blog posts on AWS (Launch Amazon ECS cluster and scaling with Amazon ECS), I had explained how to deploy 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 how to create a new revision for the existing task definition 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, just 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 EC2 instance in your cluster then to your desired number of tasks in a service configuration. For example, if your service has a desired count of two tasks then first it will start the third task and then stop one existing task. Means by using deployment strategy it will automatically run new task and stop the existing one.

Lets see how can we update service in order to run the updated version of task definition / docker images.

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

1

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

9.png

c. Click oncontainer definition” :

10.png

d. Update task definition: Here I’m updating 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 image section, if you want to go with the latest image then no need to change, 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 task definition having previous version of docker image in case you have updated the image on repository.

11.png

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

12.png

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

13.png

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

14.png

h. Running updated service:

15.png

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

In case of any confusion, don’t hesitate to ask.

Thanks !!

KNOLDUS-advt-sticker

--

--

Knoldus Inc.
Knoldus - Technical Insights

Group of smart Engineers with a Product mindset who partner with your business to drive competitive advantage | www.knoldus.com