Cloud / IaC · Freelance
ECS Blue/Green Deployments with CodeDeploy and GitHub Actions
CloudFormation stack for ECS on EC2 where CodeDeploy performs blue/green deployments with auto-rollback, driven by GitHub Actions.
// Overview
The main template provisions the cluster, an ALB with paired target groups per service, ECS services using the CodeDeploy controller, and a database instance with scheduled snapshots. Because CloudFormation lacked native support at the time, an inline Lambda-backed custom resource creates the deployment groups. A separate template builds the network. A GitHub Actions workflow lints, tests, builds, publishes images and triggers deployment.
// The problem
Zero-downtime, rollback-capable releases for containerised services.
// Flow
- Lint, test, buildGitHub Actions on push and pull request
- Image publishbuild and push to ECR
- Revision fileJSON referencing the new task definition
- CodeDeploy gateblue/green per service via a custom-resource deployment group
- ALBtwo target groups per service; listener rules switch traffic
- Rollbackautomatic on deployment failure
- Data layersnapshots on a schedule
- SecretsSecrets Manager references passed as parameters, not values
// Design decisions & guardrails
- A custom-resource Lambda fills a CloudFormation gap.
- Deploy only from protected branches; environment type is in every name.
- Secrets referenced by ARN; network in a separate template.
// Outcome
Blue/green releases with automatic rollback on failure.