Deploying Amazon ECS Services
Amazon ECS services can be updated in three ways: the ECS rolling update, ECS native blue/green, linear and canary deployments, and blue/green deployments managed by AWS CodeDeploy. This lesson explains how each works, the settings that control availability and rollback, and how to choose between them.
Learning outcomes
After completing this lesson, you will be able to:
- Explain how an ECS rolling update uses minimum healthy percent and maximum percent.
- Describe the ECS deployment circuit breaker and CloudWatch alarm-based rollback.
- Explain how ECS native blue/green, linear and canary deployments and their lifecycle hooks work.
- Distinguish between ECS native blue/green and CodeDeploy blue/green deployments for ECS.
ECS Rolling Updates
The default deployment controller, ECS, performs a rolling update when a service's task definition changes. ECS starts tasks from the new revision and stops tasks from the old one, within limits set by two parameters. minimumHealthyPercent (default 100) is the lower bound on running, healthy tasks as a percentage of the desired count, and maximumPercent (default 200) is the upper bound on running tasks of both versions. With the defaults and a desired count of 4, ECS may run up to 8 tasks and must keep 4 healthy, so it starts new tasks before stopping old ones. Lowering minimumHealthyPercent to 50 lets ECS stop old tasks first, which is useful when the cluster has no spare capacity, at the cost of reduced capacity during the deployment.
New tasks count as healthy when they pass the container health checks and, with a load balancer, the target group health checks. A health check grace period on the service tells ECS to ignore load balancer health checks for a period after a task starts, which prevents slow-starting applications from being killed before they are ready.
ECS rolling limits
Circuit Breaker and Alarm Rollback
Without protection, a rolling update of a task definition that cannot start would keep launching and stopping tasks indefinitely. The deployment circuit breaker detects that tasks are failing to reach a steady state, marks the deployment as failed after a threshold of failed tasks, and, with the rollback option enabled, returns the service to the last completed deployment. CloudWatch alarm integration adds application-level protection: if any configured alarm enters the ALARM state during the deployment, ECS fails the deployment and can roll back. The circuit breaker catches tasks that do not start or fail health checks; alarms catch tasks that run but behave badly, such as raising the error rate. Deployment state changes are published as EventBridge events.
Circuit breaker or alarm?
ECS Native Blue/Green, Linear and Canary Deployments
ECS also supports blue/green, linear and canary strategies natively with the ECS deployment controller, without CodeDeploy. In a native blue/green deployment, ECS starts a complete set of new (green) tasks registered with an alternate target group, optionally sends test traffic to them through a test listener rule, then shifts production traffic from the blue target group to the green one by changing listener rules. Blue tasks are kept for a configurable bake time, during which rollback is immediate, and are then stopped. Linear and canary strategies shift production traffic in steps rather than all at once. Traffic is shifted through an Application Load Balancer, a Network Load Balancer or ECS Service Connect, and the supported options depend on the strategy.
Native deployments support lifecycle hooks: Lambda functions invoked at stages such as after the green tasks scale up, after test traffic shifts and after production traffic shifts. A hook returns success, failure or a request to be invoked again, so it can run validation tests before production traffic moves. Alarms and the circuit breaker trigger automatic rollback as for rolling updates. Because the strategy is part of the service, the CodePipeline Amazon ECS standard deploy action and a simple service update both use it.
The following diagram shows the target groups, listener rules and hook points.

CodeDeploy Blue/Green Deployments for ECS
Before native blue/green existed, the only way to perform blue/green deployments for ECS was the CODE_DEPLOY deployment controller. It remains supported. CodeDeploy creates a replacement task set, registers it with a second target group, optionally routes a test listener to it and then shifts production traffic using an ECS deployment configuration such as CodeDeployDefault.ECSCanary10Percent5Minutes, ECSLinear10PercentEvery1Minutes or ECSAllAtOnce. Lambda hooks can run at BeforeInstall, AfterInstall, AfterAllowTestTraffic, BeforeAllowTraffic and AfterAllowTraffic. The original task set is terminated after a configurable wait. In CodePipeline, this controller is used with the ECS (blue/green) deploy action and its imageDetail.json, task definition and AppSpec inputs.
The comparison below summarises the three approaches.
Older scenarios
Exam questions written before native ECS blue/green existed expect CodeDeploy as the answer for blue/green or canary ECS deployments. Both are valid today; read the options carefully and prefer the one that meets the requirements with the least additional configuration.
Releasing a Container Service Safely
A checkout service runs 20 tasks behind an Application Load Balancer. The team wants new versions to receive 10% of traffic for 15 minutes before full release, wants an automated API test against the new tasks before any customer traffic, and wants automatic rollback if the 5xx alarm fires.
The service is configured with the ECS deployment controller and a canary strategy of 10% with a 15-minute interval, a blue and green target group pair and a test listener rule. A lifecycle hook function at the post-test-traffic stage calls the test listener and returns failure if the API test fails. The 5xx alarm is attached to the service deployment configuration with rollback enabled, and the circuit breaker is enabled to catch tasks that fail to start. The CodePipeline ECS standard deploy action starts each release from imagedefinitions.json.
A service with desired count 6 and no spare cluster capacity fails to deploy because new tasks cannot be placed. The service uses minimumHealthyPercent 100 and maximumPercent 200. What change allows the rolling update to proceed?
Show answer
Lower minimumHealthyPercent, for example to 50, so ECS can stop some old tasks before starting new ones, or add capacity through a capacity provider. With 100% minimum, ECS must start new tasks first.
Exam Tips
Remember for the exam
- Rolling updates are bounded by minimumHealthyPercent (default 100) and maximumPercent (default 200).
- The deployment circuit breaker rolls back deployments whose tasks fail to start or stay healthy; CloudWatch alarms roll back deployments that run but misbehave.
- ECS now supports native blue/green, linear and canary deployments with bake time and Lambda lifecycle hooks; CodeDeploy is no longer required for ECS blue/green.
- CodeDeploy blue/green for ECS uses the CODE_DEPLOY controller, task sets, ECS deployment configurations and the CodeDeployToECS pipeline action.
- Set a health check grace period for slow-starting containers behind a load balancer.