How do I deploy new tasks in Amazon ECS without downtime?

3 minute read
50

When I update my application on Amazon Elastic Container Service (ECS), I want to deploy new tasks without downtime or disruption to the running services.

Resolution

To launch new tasks with zero downtime, take the following actions.

Configure your deployment parameters to use a rolling update deployment type

For zero downtime deployments in Amazon ECS, it's a best practice to set the minimum healthy percent to 100% and the maximum percent to 200%. For more information about the minimum healthy perfect and maximum percent parameters, see Deployment configuration.

To configure the deployment parameters, complete the following steps:

  1. Open the Amazon ECS console.
  2. Choose Cluster.
  3. On the Clusters details page, under Services, select the service that you want to update. Then, choose Update.
  4. Under Deployment configuration, configure the Min running tasks % and Max running tasks % values.
  5. Choose Update service.

Important: Amazon ECS manages the container deployment process, but it doesn't handle traffic routing. If you use a load balancer, then configure the load balancer to route traffic to your Amazon ECS tasks. If you use blue/green deployments with AWS CodeDeploy, then check the traffic management configuration.

Configure the stopTimeout parameter of the container instance in the task definition

Set the stopTimeout parameter to make sure that your application has enough buffer time during deployment to complete task requests. Update the Amazon ECS task definition, and then on the Create new task definition revision, under Container timeouts - optional, configure the Stop timeout value.

Configure the ELB target group settings

To configure the Elastic Load Balancing (ELB) target group settings, complete the following steps:

  1. Open the Amazon EC2 console.
  2. Choose Target groups, and then select the target group that's associated with your Amazon ECS service.
  3. Choose the Group details tab. Then, configure the Health check path, Health check protocol, Health check port, Healthy threshold, and Unhealthy threshold with your values.
  4. Choose the Attributes tab, and then configure the Deregistration delay value to meet your application's needs.
    Note: It's a best practice to set the deregistration delay attribute to approximately double your application's response time.
  5. (Optional) Set up sticky sessions for your load balancer so that ongoing application request sessions complete with the existing task.

For advanced deployment strategies, use CodeDeploy

Use CodeDeploy to validate the state of the Amazon ECS service before deployment.

Note: The All-at-once blue/green deployment traffic shift can cause service disruptions.

Set up automated draining for Spot Instances

Turn on Spot Instance draining for your container instances to automatically drain instances.

AWS OFFICIAL
AWS OFFICIALUpdated a month ago
5 Comments

Thank you for providing such a comprehensive guide on achieving zero-downtime deployments in ECS. The step-by-step instructions on configuring rolling updates, stopTimeout parameters, and ELB settings are particularly valuable. This will be incredibly helpful for optimizing a deployment process.

AWS
SUPPORT ENGINEER
replied 2 days ago

Thank you for this clear explanation on zero-downtime deployments in ECS. The step-by-step approach makes it much easier to understand how to deploy the resources properly.

AWS
replied 2 days ago

I appreciate how you broke down the ECS zero-downtime deployment process. Your sequential instructions really helped clarify the proper resource deployment workflow.

AWS
replied 2 days ago

Thank you for this article! It helps to have a reference guide to see if my replication settings are correct.

AWS
replied a day ago

Awesome article, thanks for sharing

AWS
replied a day ago