Skip to content

How to Fix AWS ECS Task Stopped Reason Error

DodaTech Updated 2026-06-24 2 min read

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 ecsTaskExecutionRole with proper policies.
  • Enable ECS Exec for debugging running containers.
  • Monitor task failures with CloudWatch Events.

Common Mistakes with ecs task failure

  1. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  2. Using return to exit a function early instead of wrapping a pure value in the monad
  3. 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

Where can I find why my ECS task stopped?

Check the stoppedReason field in aws ecs describe-tasks output. Also check ECS service events and CloudWatch Logs for the stopped container. |||What is the difference between memory and memoryReservation? memory is the hard limit — the container cannot exceed this amount. memoryReservation is the soft limit — the container is guaranteed at least this much. |||How do I update an ECS service after changing the task definition? Run aws ecs update-service --cluster my-cluster --service my-service --task-definition my-app:5 to use the new revision.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro