AWS Certified Developer - Associate
Containers on AWS
Updating ECS Task
In this article, we explain how to update an Amazon ECS (Elastic Container Service) task when a new version of your application is available. This guide covers how to replace the old task version with a new one while guaranteeing that sufficient capacity is maintained during the update process.
ECS task updates rely on two key configuration parameters:
Minimum Healthy Percent:
This setting defines the minimum number of tasks that must remain in service during an update. It ensures that a specified portion of tasks stays active, preventing service downtime.Maximum Healthy Percent:
This parameter defines the maximum number of tasks allowed to run concurrently during an update. It specifies how many tasks can be temporarily added to maintain overall capacity.
During an update, ECS does not modify existing tasks directly. Instead, it terminates a portion of the running tasks and deploys new ones using the updated task definition. Consequently, both the old and new versions might run concurrently until the update process is fully complete.
Example 1: Update With Balanced Capacity
Consider a scenario where four tasks are running version 1 of your application with the following configuration:
- Minimum Healthy Percent: 25%
- Maximum Healthy Percent: 100%
With these settings:
- A minimum healthy percent of 25% means that at least one task (25% of 4) must always remain running.
- A maximum healthy percent of 100% ensures that at no time does the number of running tasks exceed four.
During the update:
- ECS removes up to three tasks at a time, ensuring that at least one task remains active.
- New tasks are deployed to replace the terminated tasks.
- Initially, you might have one task running the old version and three tasks running the new version.
- Once the new tasks are verified as healthy, the remaining old task is terminated and replaced by a new version.
Example 2: Update With Maximum Availability
Now, consider a configuration with these parameters:
- Total tasks: 4
- Minimum Healthy Percent: 100%
- Maximum Healthy Percent: 125%
This configuration implies:
- A minimum healthy percent of 100% guarantees that all four tasks remain running at all times.
- A maximum healthy percent of 125% permits the total number of tasks to temporarily increase to five during the update process.
For this setup:
- ECS launches an additional task, increasing the count to five.
- Once the new task is confirmed healthy, ECS terminates one of the original tasks running version 1.
- This cycle continues until every task is updated to version 2 while ensuring uninterrupted service availability.
Note
By carefully configuring the minimum and maximum healthy percentages, you can balance service availability with an efficient rollout of new task versions. This flexibility ensures that updates can be performed with minimal impact to your application's performance.
Conclusion
By understanding and properly setting the Minimum Healthy Percent and Maximum Healthy Percent parameters, you gain precise control over the ECS task update process. This ensures your application remains available throughout the update while seamlessly transitioning to newer versions of your tasks.
For more details on ECS task updates and best practices, refer to the Amazon ECS Documentation and other related resources.
Watch Video
Watch video content