ECS and EKS Deployments
Overview
Containers change the deployment unit from a server to an immutable image. On Amazon ECS a service keeps a desired number of tasks running from a task definition; on Amazon EKS a Kubernetes Deployment does the same with Pods. A new release is simply a new image tag plus a controlled transition.
Think of a theatre swapping its cast between acts: a rolling update replaces actors one at a time, while blue/green builds a second stage, rehearses there, and only then turns the spotlight to it. Both approaches rely on health checks so an unwell actor never walks on stage.
For DOP-C02, know the ECS deployment controllers (ECS rolling, CODE_DEPLOY blue/green and the newer ECS-native blue/green), the deployment circuit breaker, how pipelines update ECS and EKS, and Kubernetes rollout tools.
Key Concepts
- ECS rolling update is controlled by minimumHealthyPercent and maximumPercent; defaults are 100 and 200 for replica services.
- The deployment circuit breaker fails and optionally rolls back a rolling deployment that cannot reach steady state.
- ECS blue/green with CodeDeploy uses two target groups (blue and green), a prod listener and an optional test listener; traffic shifts all at once, canary or linear.
- ECS also offers built-in blue/green deployments in the service itself (introduced 2025) with lifecycle hooks via Lambda.
- The CodePipeline ECS action reads imagedefinitions.json; the CodeDeployToECS action reads appspec and taskdef files.
- Fargate and EC2 launch types both support all of these strategies; capacity providers add Spot and autoscaling.
- On EKS, Deployments use RollingUpdate (maxSurge, maxUnavailable) and readiness probes; Helm and Argo Rollouts / Flagger add canary and blue/green.
- Use ECR image digests or unique tags; never deploy mutable
latestto production.
Detailed Notes
ECS rolling updates
| Setting | Meaning | Example effect |
|---|---|---|
| minimumHealthyPercent | Lower bound of running tasks during deployment | 100 = never go below desired count |
| maximumPercent | Upper bound including new tasks | 200 = can double the task count |
With minimumHealthyPercent=50, maximumPercent=100 on 4 tasks, ECS stops two old tasks before starting new ones: cheaper but reduced capacity.
Enable the circuit breaker so a bad image does not loop forever:
{
"deploymentConfiguration": {
"deploymentCircuitBreaker": { "enable": true, "rollback": true },
"minimumHealthyPercent": 100,
"maximumPercent": 200,
"alarms": { "alarmNames": ["orders-5xx"], "enable": true, "rollback": true }
}
}
Deployment alarms trigger rollback on CloudWatch alarms during the deployment.
ECS blue/green with CodeDeploy
The service uses deploymentController: CODE_DEPLOY. CodeDeploy creates a replacement task set attached to the green target group, optionally routes test traffic on a test listener port, runs hooks, then shifts production traffic.
version: 0.0
Resources:
- TargetService:
Type: AWS::ECS::Service
Properties:
TaskDefinition: <TASK_DEFINITION>
LoadBalancerInfo:
ContainerName: web
ContainerPort: 8080
Hooks:
- BeforeInstall: "PreCheckLambda"
- AfterAllowTestTraffic: "IntegrationTestLambda"
- BeforeAllowTraffic: "WarmupLambda"
- AfterAllowTraffic: "SmokeLambda"
Configurations: CodeDeployDefault.ECSAllAtOnce, ECSCanary10Percent5Minutes, ECSLinear10PercentEvery1Minutes and similar. The old task set is terminated after a termination wait time (up to 48 hours), keeping rollback instant until then.
Native ECS blue/green
ECS now offers blue/green and its own lifecycle hooks without CodeDeploy, using a service-level deployment strategy and Lambda hooks such as POST_TEST_TRAFFIC_SHIFT. This reduces moving parts, but exam questions that mention CodeDeploy appspec for ECS are still the classic design.
Pipelines for ECS
| Action | Input | Effect |
|---|---|---|
| ECS (standard) | imagedefinitions.json (name, imageUri) | Registers a new task definition revision and triggers a rolling update |
| CodeDeployToECS | taskdef.json + appspec.yaml (with image placeholders) | Blue/green via CodeDeploy |
| CloudFormation | Template with updated image parameter | Stack update drives ECS service update |
EKS strategies
apiVersion: apps/v1
kind: Deployment
metadata: { name: orders }
spec:
replicas: 6
strategy:
type: RollingUpdate
rollingUpdate: { maxSurge: 25%, maxUnavailable: 0 }
template:
spec:
containers:
- name: web
image: 111122223333.dkr.ecr.us-east-1.amazonaws.com/orders:1.4.2
readinessProbe: { httpGet: { path: /health, port: 8080 } }
Rollback: kubectl rollout undo deployment/orders. For canary releases use a service mesh (AWS App Mesh is being retired in favour of VPC Lattice / Istio), the AWS Load Balancer Controller weighted target groups, or Argo Rollouts. In CodePipeline, a CodeBuild step runs kubectl or helm upgrade --atomic using an IAM role mapped via EKS access entries (or aws-auth).
GitOps
Argo CD or Flux pull desired state from Git into the cluster. The pipeline only commits a new image tag; the cluster reconciles. This improves audit and drift correction.
Choosing a strategy
| Need | Choice |
|---|---|
| Simple, low cost, brief mixed versions OK | ECS rolling with circuit breaker |
| Test new version with real listener before cutover, instant rollback | Blue/green |
| Gradual exposure and metric-based abort | CodeDeploy canary/linear with alarms |
Circuit breakers, health settings and Kubernetes rollouts
- ECS deployment circuit breaker (rolling updates) stops a deployment whose new tasks keep failing to reach steady state and can roll back automatically to the last completed deployment; combine with CloudWatch alarms for application-level signals.
minimumHealthyPercentandmaximumPercentset how many tasks may be stopped and started at once. For zero capacity loss use 100/200; tune the ALB deregistration delay and health check grace period so slow-starting containers are not killed.- CodeDeploy for ECS shifts ALB listener traffic between two target groups (canary, linear or all-at-once) with
BeforeAllowTrafficandAfterAllowTrafficLambda hooks. ECS also offers a built-in blue/green strategy that avoids the separate CodeDeploy application. - EKS Deployments use rolling updates governed by
maxSurgeandmaxUnavailable; readiness probes control when a pod receives traffic,PodDisruptionBudgetlimits voluntary disruption, andkubectl rollout undoreverts. Progressive delivery uses Argo Rollouts or Flux/Flagger with a service mesh or ALB weighted target groups. - Store images in ECR with immutable tags or digests and deploy by digest so a rollback is truly the previous image.
aws ecs update-service --cluster prod --service api --task-definition api:42 \
--deployment-configuration "deploymentCircuitBreaker={enable=true,rollback=true},minimumHealthyPercent=100,maximumPercent=200"
kubectl rollout status deployment/api && kubectl rollout undo deployment/api
Real World Example
Scenario: a media company runs a Fargate API. They moved from rolling updates to CodeDeploy blue/green with ECSCanary10Percent5Minutes. A test listener on port 8443 lets an integration Lambda hook exercise the green tasks before any customer traffic.
After a bad release raised latency, the alarm on target response time stopped the canary at 10% and shifted traffic back to blue in seconds. Because the old task set stayed alive for an hour, no new tasks had to start.
Architecture Diagram
Two target groups, a test listener and gradual traffic shifting.
- 1The pipeline pushes an image and produces taskdef and appspec files.
- 2CodeDeploy starts the green task set behind the green target group.
- 3Hooks and the test listener validate the new tasks.
- 4Production traffic shifts as canary or linear while alarms are watched.
- 5After the wait time the blue task set is terminated, or traffic shifts back on alarm.
Best Practices
- ✓Enable the deployment circuit breaker with rollback on every rolling ECS service.
- ✓Use unique image tags or digests, not latest.
- ✓Keep health checks and readiness probes accurate; deployments trust them.
- ✓Use a test listener and hooks to validate green before shifting production traffic.
- ✓Prefer GitOps or pipeline-driven updates with IAM-scoped roles for cluster access.
Common Interview Questions
Exam Tips
DOP-C02 focus
- ECS imagedefinitions.json = standard ECS action (rolling); appspec + taskdef = CodeDeploy blue/green.
- Test traffic before cutover = test listener + AfterAllowTestTraffic hook.
- "Automatically revert a failing ECS rolling update" = circuit breaker with rollback.
- Blue/green ECS needs two target groups on an ALB or NLB.
Finished this lesson?
0 of 44 lessons done · 0% of the course

