Blue-Green Deployments

Run the new version alongside the old, then switch all traffic at once — with instant rollback.

A blue-green deployment keeps two complete environments. Blue is live; green is the new version. You deploy and test green privately, then flip the load balancer to send all traffic to green. If anything is wrong, flip straight back to blue.

Blue-green deployment traffic switchUsersLoad balancertraffic switchBlue (v1)live nowGreen (v2)standby / new
Flip the load balancer from blue to green; roll back by flipping return.

Trade-offs

  • Instant rollback — blue is untouched and ready.
  • Cost — you run double capacity during the cutover.
  • Great for risky releases where fast recovery matters most.

Example

Example · yaml
# CodeDeploy appspec.yaml for an ECS blue-green deploy
version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: <TASK_DEFINITION>
        LoadBalancerInfo:
          ContainerName: web
          ContainerPort: 3000
Hooks:
  - BeforeAllowTraffic: validateGreenFunction
  - AfterAllowTraffic: smokeTestFunction

When to use it

  • A team runs blue-green deployments on ECS so they can instantly switch all traffic back to the old version if the new release shows errors.
  • A company uses CodeDeploy blue-green with a 10-minute traffic shift so both environments run simultaneously and smoke tests can verify the green version.
  • An ops engineer tests a major database migration on the green environment under real traffic before terminating the blue environment an hour later.

More examples

Create blue-green CodeDeploy deployment

Creates a CodeDeploy deployment that will shift 100% of traffic to the green environment at once.

Example · bash
aws deploy create-deployment \
  --application-name myapp \
  --deployment-group-name myapp-prod \
  --revision revisionType=S3,s3Location='{bucket=my-bucket,key=appspec.zip,bundleType=zip}' \
  --deployment-config-name CodeDeployDefault.AllAtOnce

AppSpec for ECS blue-green deploy

Defines the ECS blue-green deploy AppSpec pointing traffic to the new task definition and running a test hook before full cutover.

Example · yaml
version: 0.0
Resources:
  - TargetService:
      Type: AWS::ECS::Service
      Properties:
        TaskDefinition: <TASK_DEFINITION>
        LoadBalancerInfo:
          ContainerName: myapp
          ContainerPort: 3000
        PlatformVersion: LATEST
Hooks:
  - AfterAllowTestTraffic: TestHook

Manual rollback via CodeDeploy stop

Stops an in-progress deployment and triggers automatic rollback to the previous (blue) environment.

Example · bash
# If smoke tests fail, stop and roll back immediately
aws deploy stop-deployment \
  --deployment-id d-EXAMPLE \
  --auto-rollback-enabled

Discussion

  • Be the first to comment on this lesson.
Blue-Green Deployments — AWS Deployment | SoundsCode