AWS Builder Center

Blue/Green and Canary Deployments on Amazon ECS with AWS CodeDeploy and Application Load Balancer

How to achieve zero-downtime container deployments and automated rollback strategies on Amazon ECS using CodeDeploy traffic shifting.

Systems Engineer | Software & Data Solutions
Deploying updates to mission-critical containerized services carries risk. Rolling updates can sometimes mask regressions until after the deployment finishes.
To eliminate downtime and minimize blast radius, pairing Amazon Elastic Container Service (ECS) with AWS CodeDeploy and an Application Load Balancer (ALB) provides automated, verifiable canary and blue/green release workflows.



1. Architectural Components

The setup relies on three foundational elements:
  1. Target Group Pair: The ALB uses two distinct target groups: a Production Target Group routing live customer requests, and a Test Target Group used to validate new tasks.
  1. ECS Task Definition Revisions: CodeDeploy instantiates replacement task containers using the new image tag alongside the existing healthy containers.
  1. AWS CodeDeploy Controller: Governs the rerouting of traffic based on defined linear or canary timing configurations.



2. Traffic Shifting Strategies: Canary vs Linear

Rather than shifting all traffic immediately, CodeDeploy supports controlled progressive rollouts:
  • Canary Deployment ( Canary10Percent5Minutes ): Shifts 10% of incoming production traffic to the new task revision. If no alarms trigger after 5 minutes, the remaining 90% is cut over instantaneously.
  • Linear Deployment ( Linear10PercentEvery1Minute ): Shifts traffic incrementally by 10% each minute over a 10-minute rollout window, providing gradual observability across heavy traffic spikes.



3. Automated Guardrails with CloudWatch Alarms

A resilient deployment must self-heal if bugs slip into production.
By linking Amazon CloudWatch metric alarms to the CodeDeploy deployment group:
  • Monitor key indicators such as ALB HTTP 5XX Error Rate and ECS Target Response Time.
  • If an alarm enters the  ALARM  state during any phase of traffic shifting, CodeDeploy immediately aborts the deployment, shifts 100% of live traffic back to the original stable container tasks, and terminates the faulty blue tasks.



Conclusion

Automating progressive traffic shifting on Amazon ECS ensures application updates are verified against real production workloads while protecting end users through instant, automated rollbacks.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article