You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Building and testing your code is only half the story. You also need to get it onto your servers, containers, or Lambda functions — reliably and with the ability to roll back if something goes wrong. AWS CodeDeploy is a fully managed deployment service that automates application deployments to Amazon EC2 instances, on-premises servers, Lambda functions, and Amazon ECS services.
Manual deployments are error-prone and stressful. Common problems include:
CodeDeploy solves these problems by providing a repeatable, automated deployment process with built-in health checks and rollback support.
A CodeDeploy application is a logical container that groups your deployment configuration. You create one application per workload.
A deployment group defines the target environment — which EC2 instances, Lambda function, or ECS service should receive the deployment. For EC2, you can target instances by:
Environment=ProductionThe deployment configuration controls how the deployment rolls out:
| Configuration | Behaviour |
|---|---|
| AllAtOnce | Deploy to all targets simultaneously |
| HalfAtATime | Deploy to 50 % of targets, then the remaining 50 % |
| OneAtATime | Deploy to one target at a time |
| Custom | Define your own percentage or count |
For production workloads, OneAtATime or a custom rolling strategy minimises risk.
A revision is the version of your application you want to deploy. For EC2/on-premises, this is typically a ZIP or tarball in S3 or a GitHub commit. For Lambda, it is a new function version or alias. For ECS, it is a new task definition.
CodeDeploy supports three compute platforms, each with different deployment strategies:
Deploy application code and configuration to a fleet of servers. The CodeDeploy Agent must be installed on each target instance — it handles pulling the revision from S3 or GitHub and executing the deployment lifecycle hooks.
Deploy a new version of a Lambda function and shift traffic from the old version to the new version. CodeDeploy manages the alias traffic shifting.
Deploy a new task definition revision and shift traffic from the old task set to the new task set behind a load balancer.
The AppSpec file (appspec.yml) is the heart of a CodeDeploy deployment. It tells CodeDeploy what to deploy and how.
version: 0.0
os: linux
files:
- source: /
destination: /var/www/myapp
permissions:
- object: /var/www/myapp
owner: www-data
group: www-data
mode: "755"
hooks:
BeforeInstall:
- location: scripts/stop-server.sh
timeout: 60
AfterInstall:
- location: scripts/install-dependencies.sh
timeout: 120
ApplicationStart:
- location: scripts/start-server.sh
timeout: 60
ValidateService:
- location: scripts/health-check.sh
timeout: 120
CodeDeploy executes hooks in a fixed order during each deployment:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.