AWS Certified DevOps Pro: Deployment Strategies for Instance, Container, and Serverless Environments
Implement deployment strategies for instance, container, and serverless environments
Advanced Deployment Strategies in AWS
This guide covers the critical strategies for deploying applications across various AWS compute platforms, focusing on the methodologies, tools, and best practices required for the DOP-C02 exam.
Learning Objectives
By the end of this module, you should be able to:
- Distinguish between mutable and immutable deployment patterns.
- Configure AWS CodeDeploy for EC2/On-premises, ECS, and Lambda platforms.
- Implement Blue/Green and Canary deployment strategies to minimize downtime.
- Define lifecycle event hooks in
appspec.ymlfor different compute types. - Select appropriate storage patterns (EBS, EFS, S3) based on application persistence needs.
Key Terms & Glossary
- AppSpec File: A configuration file (YAML/JSON) used by CodeDeploy to manage the deployment lifecycle.
- In-place Deployment: An update method where the application on each instance is stopped, updated, and restarted. (EC2 only).
- Blue/Green Deployment: A strategy where a new environment (Green) is provisioned alongside the old one (Blue). Traffic is shifted once the Green environment is validated.
- Canary Deployment: A phased deployment where a small percentage of traffic is shifted to the new version before a full rollout.
- Immutable Infrastructure: A pattern where servers are never modified after deployment; updates involve replacing the entire instance or container.
- Mutable Infrastructure: A pattern where existing servers are updated in-place (e.g., via SSH or configuration management).
The "Big Idea"
In a DevOps environment, the goal is Zero-Downtime Deployment. AWS provides a spectrum of tools to achieve this, ranging from the highly customizable CodeDeploy to the automated orchestration of ECS and Lambda. The choice of strategy depends on the Compute Platform (is it a server, a container, or code?) and the Risk Tolerance (how much traffic can we risk on unvalidated code?).
Formula / Concept Box
| Feature | EC2/On-Premises | Amazon ECS | AWS Lambda |
|---|---|---|---|
| AppSpec Format | YAML only | YAML or JSON | YAML or JSON |
| Deployment Types | In-place & Blue/Green | Blue/Green | Canary & Linear |
| Traffic Shifting | Load Balancer / DNS | ALB / NLB Target Groups | Lambda Aliases |
| Agent Required? | Yes (CodeDeploy Agent) | No | No |
| Persistence | EBS / EFS / S3 | EFS / S3 | S3 / EFS (Mountable) |
Hierarchical Outline
- I. Deployment Methodologies
- A. Mutable (In-Place): Updates existing resources. Slower recovery, risk of "configuration drift."
- B. Immutable (Replacement): Replaces resources. Faster rollbacks, consistent state.
- II. AWS CodeDeploy Architecture
- A. Deployment Groups: Logical tags for environments (Staging vs. Production).
- B. AppSpec Lifecycle Hooks:
- EC2 Hooks:
BeforeInstall,AfterInstall,ApplicationStart,ValidateService. - Lambda Hooks:
BeforeAllowTraffic,AfterAllowTraffic.
- EC2 Hooks:
- III. Platform-Specific Strategies
- A. Amazon EC2: Supports Auto Scaling Group (ASG) integration for automatic deployment to new instances.
- B. Amazon ECS: Utilizes Task Sets; requires an ELB to swap traffic between Blue and Green.
- C. AWS Lambda: Uses Aliases and Weights to shift traffic (e.g.,
Canary10Percent5Minutes).
Visual Anchors
Blue/Green Deployment Workflow
Infrastructure Modification Patterns
Definition-Example Pairs
- Linear Deployment: Traffic is shifted in equal increments over time.
- Example: Shifting 10% of Lambda traffic every 10 minutes until 100% is reached.
- AppSpec
ValidateServiceHook: A script used to verify the deployment was successful.- Example: A curl command sent to the local endpoint
localhost:80/healthto ensure the web server is responding before marking the deployment 'Succeeded'.
- Example: A curl command sent to the local endpoint
- EC2 Image Builder: An automated service to create and maintain "Golden Images" (AMIs).
- Example: A pipeline that triggers every month to patch an Amazon Linux AMI, installs security agents, and shares it with the Production AWS account.
Worked Examples
Scenario: Converting an EC2 In-place Update to Blue/Green
The Problem: A company updates their EC2 instances using git pull on each server. This causes 5 minutes of downtime and occasionally leaves servers in inconsistent states.
The Solution:
- Artifact Preparation: Use CodeBuild to bundle the application into a
.zipfile and push to S3. - AppSpec Update: Create an
appspec.ymlthat defines thedestinationfor files and uses theApplicationStarthook to launch the service. - CodeDeploy Configuration: Create a Blue/Green deployment group. Select the Auto Scaling Group currently running the app.
- Traffic Shifting: Configure CodeDeploy to use an Application Load Balancer (ALB).
- Execution: When deploying, CodeDeploy clones the ASG, installs the new version on the new instances, and swaps the ALB target group once
ValidateServicepasses.
Checkpoint Questions
- Which compute platform allows for In-place deployments via AWS CodeDeploy?
- In a Lambda deployment, which AppSpec hook would you use to run a functional test before the traffic starts shifting?
- What is the primary difference between a Canary and a Linear deployment strategy?
- True or False: The CodeDeploy agent must be installed on ECS Fargate tasks to perform a deployment.
▶Click to see Answers
- Amazon EC2 / On-premises.
BeforeAllowTraffic.- Canary shifts a single chunk (e.g., 10%) then the rest; Linear shifts increments at set intervals (e.g., 10% every X minutes).
- False. ECS deployments are handled via the ECS service and task sets; no agent is needed within the container.
Muddy Points & Cross-Refs
- AppSpec vs. BuildSpec: Remember that
buildspec.ymlis for CodeBuild (compiling code/creating artifacts), whileappspec.ymlis for CodeDeploy (placing files/running hooks). - ECS Deployment Errors: A common failure point is the
TaskDefinitionexecution role. Ensure the role has permissions to pull the image from ECR, otherwise, the Blue/Green swap will time out. - Rollbacks: CodeDeploy rollbacks are automatic by default on failure, but for Blue/Green, you must specify whether to terminate the original instances immediately or keep them for manual inspection.
Comparison Tables
Deployment Method Comparison
| Feature | In-place | Blue/Green | Canary |
|---|---|---|---|
| Risk Level | High | Low | Lowest |
| Cost | Low (No extra resources) | High (Double capacity during deploy) | Medium |
| Rollback Speed | Slow (Must redeploy old version) | Fast (Flip LB back to Blue) | Fast (Redirect traffic) |
| Downtime | Potential | Zero | Zero |
| Use Case | Dev/Test environments | Production Web Apps | Critical API Updates |