1. Overview
Automated deployment to EC2, on-premises, Lambda, and ECS. Uses appspec.yml.
Core appspec.yml defines deployment. In-Place or Blue/Green for EC2. Canary/Linear/AllAtOnce for Lambda/ECS.
2. EC2 Strategies
3. Lambda/ECS Strategies
4. appspec.yml
version: 0.0
os: linux
files: [{ source: /, destination: /var/www/app }]
hooks:
BeforeInstall: [scripts/stop.sh]
AfterInstall: [scripts/deps.sh]
ApplicationStart: [scripts/start.sh]
ValidateService: [scripts/health.sh]- Lifecycle order: ApplicationStop → DownloadBundle → BeforeInstall → Install → AfterInstall → ApplicationStart → ValidateService
- CodeDeploy Agent required on EC2 (NOT Lambda/ECS)
- Auto rollback on failure or CloudWatch alarm
- ECS = Blue/Green ONLY via ALB
5. When to use
Use CodeDeploy when you need to automate application deployments to EC2, on-premises servers, Lambda, or ECS.
Common scenarios:
- Deploy to EC2 fleets — Push new application versions to groups of EC2 instances.
- On-premises deployments — Deploy to your own data center servers using the same tool.
- Lambda function updates — Gradually shift traffic to a new Lambda version.
- ECS service updates — Blue/green deployments for containerized applications.
- CI/CD pipeline — Integrate with CodePipeline, GitHub, Jenkins, or S3 for automated releases.
- Minimize downtime — Use rolling or blue/green strategies to avoid full outages.
Exam Tip CodeDeploy: appspec.yml. In-Place vs Blue/Green (EC2). Canary/Linear (Lambda/ECS). ECS=Blue/Green only. Agent on EC2 only.