How to Fix AWS ECS Task Stopped Reason Error
In this tutorial, you'll learn about How to Fix AWS ECS Task Stopped Reason Error. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.
Your ECS task starts then immediately stops — the stoppedReason field reveals why, ranging from resource limits to configuration errors.
Step-by-Step Fix
1. Get the stopped reason
aws ecs describe-tasks --cluster my-cluster --tasks arn:aws:ecs:us-east-1:123456789012:task/my-cluster/abc123
Expected output:
{
"tasks": [
{
"stoppedReason": "CannotPullContainerError: pull image manifest: manifest for nginx:latest not found",
"lastStatus": "STOPPED",
"desiredStatus": "STOPPED]
}
]
}
2. Fix common stopped reasons
Resource:Memory — increase memory in task definition:
{
"family": "my-app",
"containerDefinitions": [{
"memoryReservation": 512,
"memory": 1024
}]
}
Register the updated definition:
aws ecs register-task-definition --cli-input-json file://task-def.json
3. Check ECS service events
aws ecs describe-services --cluster my-cluster --services my-service --query 'services[0].events'
4. Verify task execution role
aws iam get-role --role-name ecsTaskExecutionRole --query 'Role.AssumeRolePolicyDocument'
5. Check CloudWatch Logs
aws logs get-log-events --log-group-name /ecs/my-task --log-stream-name my-task/abc123
Common Mistakes
| Mistake | Fix |
|---|---|
| Container image not found | Check image name and tag in task definition |
| Insufficient memory | Increase task memory or reduce container footprint |
| Insufficient CPU | Increase task CPU in the task definition |
| Execution role missing | Attach AmazonECSTaskExecutionRolePolicy |
| Secrets Manager access denied | Add secretsmanager:GetSecretValue to execution role |
Prevention
- Set appropriate CPU and memory reservations.
- Use the
ecsTaskExecutionRolewith proper policies. - Enable ECS Exec for debugging running containers.
- Monitor task failures with CloudWatch Events.
Common Mistakes with ecs task failure
- Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
- Using
returnto exit a function early instead of wrapping a pure value in the monad - Mixing let bindings with <- bindings in do notation, producing type errors
These mistakes appear frequently in real-world AWS code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.
Practice Exercise
Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.
This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.
FAQ
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro