THE DEV SPECTRUM

Back to Spectrum

Zero-Downtime Deploys: A Practical Guide to Blue-Green Strategies on AWS

In a CI/CD world, the most dangerous moment is the "Cutover." Blue-Green deployment is the strategy of having two identical production environments. Only one (Blue) is serving live traffic, while the other (Green) is where you deploy the new version.

The Role of the Load Balancer

Using an AWS Application Load Balancer (ALB), you can shift traffic between Target Groups. This is significantly faster than waiting for DNS TTLs to expire.

The Deployment Script

We automate this using a simple shell script within our CI/CD pipeline that updates the ALB Listener Rule:

# Update ALB Target Group to Green environment
aws elbv2 modify-listener \
  --listener-arn ${LISTENER_ARN} \
  --default-actions Type=forward,TargetGroupArn=${GREEN_TARGET_GROUP_ARN}

Why it Matters

By using this pattern, if the Green environment shows a spike in 5xx errors (which we catch with the Prometheus monitoring we set up in our last post!), we can instantly flip the traffic back to Blue with zero impact on the users.