2.1.1.5. Deployment Strategies Overview (CodeDeploy)
2.1.1.5. Deployment Strategies Overview (CodeDeploy)
CodeDeploy automates application deployments to EC2 instances, ECS services, Lambda functions, and on-premises servers. The critical concept is that CodeDeploy uses different deployment types depending on the compute platform — and the exam tests whether you can match the right type to the right scenario.
EC2/On-Premises deployments use an appspec.yml that defines lifecycle hooks:
version: 0.0
os: linux
files:
- source: /
destination: /var/www/html
hooks:
BeforeInstall:
- location: scripts/stop_server.sh
timeout: 300
AfterInstall:
- location: scripts/start_server.sh
timeout: 300
ValidateService:
- location: scripts/health_check.sh
timeout: 300
EC2/on-premises hook order (in-place): ApplicationStop → BeforeInstall → AfterInstall → ApplicationStart → ValidateService — the last application hook, where post-deployment health checks belong. With a load balancer, BeforeBlockTraffic/AfterBlockTraffic run first and BeforeAllowTraffic/AfterAllowTraffic run after ValidateService.
ECS deployments use a different appspec.yml format that specifies the new task definition and container port. CodeDeploy handles the traffic shifting between the original (blue) and replacement (green) target groups behind an ALB. An optional test listener sends test traffic to the green task set before any production traffic moves. ECS hooks are Lambda functions at BeforeInstall, AfterInstall, AfterAllowTestTraffic, BeforeAllowTraffic, and AfterAllowTraffic; a hook that reports failure fails the deployment, and with rollback enabled traffic stays on (or returns to) the blue task set.
Lambda deployments shift traffic between function alias versions. appspec.yml specifies BeforeAllowTraffic and AfterAllowTraffic hooks — Lambda functions that run validation before and after the traffic shift.
| Compute Platform | Deployment Types | Rollback Method |
|---|---|---|
| EC2/On-Premises | In-Place, Blue/Green | Redeploy previous revision |
| ECS | Blue/Green only (Canary, Linear, or All-at-once traffic shift) | Reroute traffic to original task set |
| Lambda | Canary, Linear, All-at-once | Shift traffic back to original version |
Exam Trap: EC2 Blue/Green needs a load balancer and a replacement fleet — CodeDeploy can copy an existing Auto Scaling group to create the green instances, or you provision them manually before the deployment. Once traffic moves, the original instances are terminated or kept running, as configured. On-premises servers can't use Blue/Green; they are limited to In-Place.