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:
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:
- Open the Amazon ECS console.
- In the navigation pane, choose Clusters.
- Select your cluster.
- Choose the Infrastructure tab.
- 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