Skip to content

How do I troubleshoot a stopped Amazon ECS task?

6 minute read
4

I want to troubleshoot my Amazon Elastic Container Service (Amazon ECS) task that stopped.

Resolution

Troubleshoot a stopped task

Use the DescribeTasks API call to view the details of a stopped task. The details include a stopped reason and exit code that can help you troubleshoot the stopped task. The details for the stopped task appear only for 1 hour in the API results. To allow more time to view stopped task details, use the amazon-ecs-stopped-tasks-cwlogs template on the GitHub website.

Essential container in task exited

If your essential container exited, then use one of the following exit codes to troubleshoot your issue:

  • The 0 exit code occurs when the entry point, success, or CMD command is complete and Amazon ECS stops the container.
  • The 1 exit code occurs when there's an application error. To troubleshoot this exit code, review your application logs.
  • The 137 exit code occurs when you don't respond to a SIGTERM within 30 seconds. Amazon ECS stops the container with SIGKILL. To change the default 30-second period, update the Amazon ECS container agent with the ECS_CONTAINER_STOP_TIMEOUT parameter.
    Note: This exit code also occurs because of out-of-memory errors. To check your resource usage, review your Amazon CloudWatch metrics for Amazon ECS.
  • The 139 exit code occurs when your application tried to access a memory region that isn't available. This exit code also occurs when an unset or environment placeholder that's not valid causes a segmentation fault. To troubleshoot this issue, review the CloudWatch logs for your Amazon ECS tasks.
  • The 143 exit code occurs when the container receives a graceful shutdown warning, and then Amazon ECS shuts down the container.
  • The 255 exit code occurs when the ENTRYPOINT CMD command in your container fails because of an error. To confirm that your container fails because of an error, review your CloudWatch logs.

For more troubleshooting steps, see How do I troubleshoot Amazon ECS tasks that stop or fail to start when my container exits?

CannotPullContainerError

This "CannotPullContainerError" error occurs when the task failed to start because Amazon ECS can't retrieve the specified container image. Resolve this issue for Amazon ECS tasks that use an Amazon Elastic Compute Cloud (Amazon EC2) launch type or AWS Fargate launch type.

Task failed Elastic Load Balancer health checks

Resolve this issue for tasks that use the EC2 launch type or Fargate launch type.

Failed container health checks

You define health checks in the HealthCheck API or the Dockerfile. For more information, see HEALTHCHECK on the Docker website. To troubleshoot container health check errors, see How do I troubleshoot container health check failures for Amazon ECS tasks?

Port is unhealthy

Errors that contain "Instance i-## port # is unhealthy" occur when an unhealthy Amazon EC2 instance doesn't respond to health checks on the specified port.

To troubleshoot this issue, take the following actions:

  • Confirm that the security group that's attached to the container instance allows the required traffic.
  • To confirm that the backend responds without delay, run the following command:
    curl -iv localhost:CONTAINER-PORT/PATH
    Note: Replace CONTAINER-PORT with your container port and PATH with your health check path.
  • Increase the response timeout value from the default 30 seconds. Update the Amazon ECS container agent with the ECS_CONTAINER_STOP_TIMEOUT parameter.

For more information about this error message, see Access logs for your Network Load Balancer.

Amazon ECS service scaling event activated

During an Amazon ECS service scaling event, tasks stop because the scaling policy reduces the number of tasks that run in Amazon ECS. Then, Amazon ECS stops tasks to reach the new specified number.

To resolve this issue, create CloudWatch alarms for changes in your service or tasks. Then, review scheduled deployments that might affect your tasks.

To protect your tasks from scale-in event termination because of service auto scaling or deployments, use Amazon ECS task scale-in protection. For more information, see How do I view and manage scheduled scaling actions for Amazon ECS services?

Task that a user stopped

To identify the user who initiates a StopTask API call, view StopTask in AWS CloudTrail for userIdentity information.

ResourceInitializationError

The "ResourceInitializationError" error occurs when Amazon ECS fails to initialize the required resources for your task.

To resolve this error, check the troubleshooting guide for your specific error message. If you have pull secrets or registry errors, see How do I resolve a "ResourceInitializationError" when I try to pull secrets or retrieve Amazon ECR authentication for ECS tasks? If you have a logger args error, see How do I resolve the "ResourceInitializationError: failed to validate logger args" error in Amazon ECS?

SpotInterruptionError

For more information about "SpotInterruptionError" errors, see Troubleshooting Amazon ECS SpotInterruption errors. To troubleshoot this error, see How do I handle Spot termination notices in AWS Fargate Spot tasks?

OutOfMemoryError

Th "OutOfMemoryError" error occurs when a container exits because processes in the container use more memory than you allocate in the task definition. To troubleshoot this error, see How do I troubleshoot OutOfMemory errors in Amazon ECS?

Troubleshoot error messages that you receive when your task stops

If you receive an error message when your task stops, then take the following troubleshooting actions based on the error.

No Container Instances were found in your cluster

To resolve this issue, launch a container instance.

To review the instances for your cluster, complete the following steps:

  1. Open the Amazon ECS console.
  2. In the navigation pane, choose Clusters.
  3. Select your cluster.
  4. Choose the Infrastructure tab.
  5. Review the Container instances section. If there are no container instances, then see Why can't my Amazon EC2 instance join the Amazon ECS cluster?

InvalidParameterException

To resolve the "InvalidParameterException" error message, check that the parameters in your TaskDefinition exist and have the correct Amazon Resource Names (ARNs). Confirm that the task role and task execution role have the required permissions.

"Limit exceeded" error

The "Limit exceeded" error occurs when you exceed an Amazon ECS service quota. To troubleshoot this issue, see How do I resolve Amazon ECS service quota issues?

Troubleshoot unexplained task stops on Fargate

If you ruled out application-level causes and your Fargate tasks still stop unexpectedly, then the issue might be related to the underlying Fargate infrastructure.

Infrastructure maintenance

The stopped reason shows that Amazon ECS performed maintenance on the Fargate servers that run your application containers. For more information, see Task retirement and maintenance for AWS Fargate on Amazon ECS. For standalone tasks, see How do I take action on an Amazon ECS task retirement notice for a task that runs on Fargate?

Other issues

If the stopped reason doesn't indicate maintenance and you exhausted all application-level troubleshooting, then contact AWS Support to request a Fargate infrastructure investigation. Provide the task ARN, cluster name, AWS Region, and the approximate time when the task stopped.

Related information

Resolve Amazon ECS stopped task errors

Viewing Amazon ECS stopped task errors

6 Comments

I am getting errors from the ECS service with error code 139, while I check from inside the container using ECS execute-command the memory usage for the container is around 700MB, it is assigned 8GB for the ECS task definition and the soft limit is 1024 and hard limit is 8000

is there any way to troubleshoot this error in the AWS ECS service?

Also, one thing I noticed is even though I have added 8GB as container memory in the task definition why the total memory is showing as 16GB while I check the free -m using ECS execute-command

replied 3 years ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

AWS
MODERATOR

replied 3 years ago

I am getting an error with exit code 0. I am able to successfully call the task and get the response. After then, the task automatically stops itself and recreate a new one. I want to have the same task because the calls must be done with the same IP address.

replied 2 years ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

AWS
MODERATOR

replied 2 years ago

Getting the below error in th console

Exit code: -
CannotStopContainerError: Error response from daemon: cannot stop container: 30b9474d3dd07395165d312e51e48c781c86125131d8b12cabc783a92b769e0: tried to kill container, but did not receive an exit event

But container is still running the backend ec2, try to kill and stop the container with docker native commands, nothing working, what could be the issue

replied a year ago

This article was reviewed and updated on 2026-07-24.

EXPERT

replied 4 months ago