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]
  1. Lifecycle order: ApplicationStop → DownloadBundle → BeforeInstall → Install → AfterInstall → ApplicationStart → ValidateService
  2. CodeDeploy Agent required on EC2 (NOT Lambda/ECS)
  3. Auto rollback on failure or CloudWatch alarm
  4. 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:

  1. Deploy to EC2 fleets — Push new application versions to groups of EC2 instances.
  2. On-premises deployments — Deploy to your own data center servers using the same tool.
  3. Lambda function updates — Gradually shift traffic to a new Lambda version.
  4. ECS service updates — Blue/green deployments for containerized applications.
  5. CI/CD pipeline — Integrate with CodePipeline, GitHub, Jenkins, or S3 for automated releases.
  6. 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.