An ECS deployment rolls back automatically, and the event says `deployment failed: tasks failed to start` from the circuit breaker.
AdvancedTroubleshootingECS, EKS, ECR and Lambda
Answer
Likely causes → The new tasks crash at startup (bad config or secret, failed migration), fail the container health check, or fail ALB health checks before healthCheckGracePeriodSeconds. The deployment circuit breaker detected repeated failures and rolled back.
Diagnose →
aws ecs describe-services --cluster prod --services api \
--query 'services[].[deployments,events[:10]]'
aws ecs list-tasks --cluster prod --service-name api --desired-status STOPPED
aws ecs describe-tasks --cluster prod --tasks <stopped-task> --query 'tasks[].[stoppedReason,containers[].[exitCode,reason]]'
aws logs tail /ecs/api --since 20m --filter-pattern ERROR
Fix →
- Fix the root cause from the stopped-task reasons and logs
- If the app is slow to start, raise
healthCheckGracePeriodSecondsand the container health checkstartPeriod - Redeploy
Prevent → Keep the circuit breaker with rollback on, add CloudWatch alarm-based rollback, and smoke-test images in staging with the same task definition.
More on ECS, EKS, ECR and Lambda
`docker push 111111111111.dkr.ecr.us-east-1.amazonaws.com/api:1.4` fails with `no basic auth credentials` (or `denied: Your authorization token has expired. Reauthenticate and try again.`).BeginnerFargate tasks stop with `CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref ... dial tcp 52.x.x.x:443: i/o timeout`.Intermediate`ResourceInitializationError: unable to pull secrets or registry auth: ... AccessDeniedException: User: arn:aws:sts::111111111111:assumed-role/ecsTaskExecutionRole/... is not authorized to perform: secretsmanager:GetSecretValue`.IntermediateA task stops with `Essential container in task exited`, exit code 137, and reason `OutOfMemoryError: Container killed due to memory usage`.BeginnerThe ECS service event says `service api was unable to place a task because no container instance met all of its requirements. The closest matching container-instance ... has insufficient memory available.`Intermediate`aws ecs execute-command` fails: `The execute command failed because execute command was not enabled when the task was run or the execute command agent isn't running.`Intermediate