AWS in 1 Min · Episode 172

AWS CodeDeploy explained: gradual releases and automatic rollback

Ship gradually, roll back fast. Watch the one-minute video, then read the details.

David Gomez1:15 video · 2 min read

"Deploying means everyone gets it at once." It shouldn't. Push a bug to every server and every user at the same moment, and your customers find it before your monitoring does. AWS CodeDeploy automates releases so they happen gradually, with checks along the way and an automatic way back.

Three places it deploys

CodeDeploy works with three compute platforms:

  • EC2 and on-premises servers, using the CodeDeploy agent.
  • AWS Lambda functions, by shifting traffic between versions with an alias.
  • Amazon ECS services, by shifting traffic between task sets behind a load balancer.

Servers: in place or blue/green

On EC2, an in-place deployment updates instances in batches, controlled by a minimum number of healthy hosts. The predefined configurations are OneAtATime (the default), HalfAtATime and AllAtOnce, and you can define your own, including per-Availability Zone limits.

A blue/green deployment instead launches a fresh set of instances with the new version, then reroutes the load balancer to them. The old fleet stays available until you terminate it, which makes going back fast.

Lambda and ECS: shifting traffic

For Lambda and ECS, CodeDeploy moves traffic, not files:

  • Canary: a first slice, for example 10 percent, then the remaining 90 percent after a wait (configurations such as LambdaCanary10Percent5Minutes).
  • Linear: equal steps, for example 10 percent every minute, until all traffic has moved.
  • All at once: everything immediately.

Hooks and rollback

The AppSpec file describes the deployment and its lifecycle hooks: scripts on servers, or Lambda functions such as BeforeAllowTraffic, that test the new version before it receives traffic. If a hook reports failure, the deployment stops.

Attach CloudWatch alarms to the deployment group and turn on automatic rollback. If error rate or latency alarms fire during the deployment, CodeDeploy rolls back to the last known good version without waiting for a person. A common mistake is enabling canary without alarms: ten percent of users get the bug, nothing notices, and five minutes later everyone has it.

For ECS, note that since 2025 the service itself also offers built-in blue/green, linear and canary deployments with alarm-based rollback, so new ECS services may not need CodeDeploy at all. Compare both before you choose.

Where AI fits

Prompts and model choices are releases too. Put a new prompt or model ID in a new Lambda version, and let CodeDeploy canary it to ten percent of requests. Watch alarms on errors, latency, or a custom metric such as a quality or cost signal your function publishes. If any alarm fires, CodeDeploy shifts everyone back to the old version, and the old prompt, automatically. It is the same safety net you use for code, applied to the part of an AI app that changes most often.

Quick recap

  • Never everyone at once: batches on servers, canary or linear on Lambda and ECS.
  • Lifecycle hooks test the new version before it gets traffic.
  • CloudWatch alarms trigger automatic rollback, for code and for prompts.
AWS in 1 Min #172 · 1:15

Need an AWS expert on your team?

I'm David, an AWS expert and fractional cloud consultant. I work alongside your team to run your cloud and infrastructure: architecture, security, cost and day-to-day operations. You get senior AWS experience when you need it, without the cost of a full-time hire.

  • Architecture reviews and a clear plan for what to fix first
  • Security hardening: IAM, networking, audits
  • Lower AWS bills without slowing your team down
  • Hands-on help with AI workloads on AWS