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.
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
# 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: smokeTestFunctionWhen 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.
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.AllAtOnceAppSpec 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.
version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: <TASK_DEFINITION>
LoadBalancerInfo:
ContainerName: myapp
ContainerPort: 3000
PlatformVersion: LATEST
Hooks:
- AfterAllowTestTraffic: TestHookManual rollback via CodeDeploy stop
Stops an in-progress deployment and triggers automatic rollback to the previous (blue) environment.
# If smoke tests fail, stop and roll back immediately
aws deploy stop-deployment \
--deployment-id d-EXAMPLE \
--auto-rollback-enabled
Discussion