Deploying ECS Services Safely and Troubleshooting Tasks
This lesson explains how to deploy new versions of ECS services safely and diagnose tasks that fail to start or keep stopping.
Learning outcomes
After completing this lesson, you will be able to:
- Choose rolling, blue/green or other deployment options.
- Find why tasks stop.
- Use container logs for diagnosis.
Deployment options
ECS services support several deployment strategies. A rolling update replaces tasks gradually, controlled by minimumHealthyPercent and maximumPercent; for example 100 and 200 start all new tasks before stopping old ones. The deployment circuit breaker detects tasks that repeatedly fail to reach a steady state and, with rollback enabled, returns the service to the last completed deployment; CloudWatch alarms attached to the deployment trigger rollback on application metrics. Since 2025 ECS also has built-in blue/green, linear and canary deployments with ALB, NLB or Service Connect: the new revision runs alongside the old one, traffic shifts all at once, in equal steps or with a small canary first, bake times allow monitoring, lifecycle hooks run validation Lambda functions, and rollback is immediate. These previously required AWS CodeDeploy.
The following diagram shows a rolling update and the circuit breaker's rollback.

Rolling update capacity
Why tasks stop
Stopped tasks keep a stoppedReason and per-container exit codes for about an hour in describe-tasks, and ECS sends task state change events to EventBridge, which can be captured to keep a longer history. The following table lists common causes.
| Symptom | Cause | Fix |
|---|---|---|
| CannotPullContainerError | No route to ECR (private subnet without NAT or endpoints), missing execution role permissions, wrong image tag | Add NAT or ECR api/dkr and S3 gateway endpoints; fix the role or tag |
| ResourceInitializationError: unable to pull secrets | Execution role cannot read the secret or KMS key, or no route to Secrets Manager | Grant permissions; add an endpoint |
| Exit code 137, OutOfMemoryError | Container exceeded its memory limit | Raise memory or fix a leak |
| Task failed ELB health checks | Wrong health check path or port, slow start | Fix the target group or health check grace period |
| Essential container exited | Application crashed; exit code 1 | Check the container logs |
| Tasks stay PENDING/PROVISIONING | No capacity, ENIs or IP addresses | Scale capacity; check subnet IPs |
Why did the task stop?
Container logs
Container logs are the first place to look for application failures. With the awslogs driver, each container's output goes to a CloudWatch log stream named with the prefix, container name and task ID. FireLens routes logs through Fluent Bit to several destinations. ECS Exec, built on Session Manager, opens a shell inside a running container for live debugging, if enabled on the service and permitted to the task role.
A deployment that never finishes
A new task definition revision is deployed with the circuit breaker and rollback enabled. New tasks start, fail ALB health checks after 30 seconds and are replaced. After several failures the circuit breaker marks the deployment failed and rolls back to the previous revision, so the service never loses capacity. The stopped tasks show Task failed ELB health checks; the logs show the application now listens on port 8081 while the task definition still maps 8080. Fixing the port mapping and redeploying succeeds.
Which two settings control capacity during an ECS rolling update?
Show answer
minimumHealthyPercent and maximumPercent.
Exam Tips
Remember for the exam
- Rolling updates use minimumHealthyPercent and maximumPercent.
- The deployment circuit breaker with rollback reverts failed deployments automatically.
- ECS has native blue/green, linear and canary deployments with bake times and lifecycle hooks.
- CannotPullContainerError in private subnets: add NAT or ECR and S3 endpoints.
- Exit code 137 means out of memory.