Lesson 2 of 4 Amazon ECS, Amazon EKS and Amazon ECR

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.

An ECS rolling update with the circuit breaker. With minimumHealthyPercent 100 and maximumPercent 200, all new tasks start before old ones stop. If new tasks repeatedly fail to reach a steady state, the deployment circuit breaker stops the deployment and, with rollback enabled, returns to the last completed deployment.
The counts are illustrative. Without the circuit breaker, a failing deployment keeps retrying.
Fill in the value

Rolling update capacity

Exam skills 3.1.5

Work out how many tasks run during an ECS rolling update.

Log in to try this activity Interactive activities are free with an account.

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.

SymptomCauseFix
CannotPullContainerErrorNo route to ECR (private subnet without NAT or endpoints), missing execution role permissions, wrong image tagAdd NAT or ECR api/dkr and S3 gateway endpoints; fix the role or tag
ResourceInitializationError: unable to pull secretsExecution role cannot read the secret or KMS key, or no route to Secrets ManagerGrant permissions; add an endpoint
Exit code 137, OutOfMemoryErrorContainer exceeded its memory limitRaise memory or fix a leak
Task failed ELB health checksWrong health check path or port, slow startFix the target group or health check grace period
Essential container exitedApplication crashed; exit code 1Check the container logs
Tasks stay PENDING/PROVISIONINGNo capacity, ENIs or IP addressesScale capacity; check subnet IPs
Match the pairs

Why did the task stop?

Exam skills 3.1.3 · 1.2.1

Match each stopped task symptom with its fix.

Log in to try this activity Interactive activities are free with an account.

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.

Worked example

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.

Check yourself

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.