Skip to content

How do I troubleshoot target deregistration issues for my Amazon ECS task?

4 minute read
0

My Amazon Elastic Container Service (Amazon ECS) task got deregistered from the target group.

Resolution

Note: If you receive errors when you run AWS Command Line Interface (AWS CLI) commands, then see Troubleshooting errors for the AWS CLI. Also, make sure that you're using the most recent AWS CLI version.

If your Amazon ECS task gets deregistered from the target group, then check the task for error messages. Or, run the following describe-tasks AWS CLI command:

aws ecs describe-tasks \
    --cluster cluster-name \
    --tasks task-ARN

Note: Replace cluster-name with the cluster name and task-ARN with your task ARN. Stopped task details are available for only 1 hour after the tasks stops.

Check the exitCode, reason, stopCode, and stoppedReason in the command's output, and then troubleshoot the stopped task.

Check whether an essential container in the task exited

All tasks must have at least one essential container. If the essential container fails or stops, then Amazon ECS stops all containers in the task. To investigate further, check your application logs.

If your task uses the awslogs log driver, then run the following get-log-events command to check your application logs in Amazon CloudWatch:

aws logs get-log-events \
--log-group-name awslogs-group \
--log-stream-name awslogs-stream-prefix/container-name/task-id

Note: Replace awslogs-group with the log group name, awslogs-stream-prefix with the name of the log stream, container-name with the container name, and task-id with the task ID.

For an example task definition that sends logs to CloudWatch, see Example Amazon ECS task definition: Route logs to CloudWatch.

Check for OutofMemory issues

If the container's processes consume more memory than the amount that you allocated in the task definition, then your task container exits.

To resolve this issue, allocate more memory to the container. It's a best practice to load test and fine tune memory parameters in a non-production environment. It's also a best practice to incrementally increase memory, and then monitor performance. For example, increase 256 MB to 512 MB. When you update your task memory, also review your CPU allocation. For more information, see Best practices for Amazon ECS task sizes.

To update the memory, check whether you defined memory in the container or in the task definition. Update the task definition, and then update the service to use the new task definition revision. Monitor the service to make sure that the task definition successfully deploys with the new memory settings.

For more troubleshooting steps, see How do I troubleshoot OutOfMemory errors in Amazon ECS?

Check your health check settings

To troubleshoot health check failures for AWS Fargate tasks, see How do I troubleshoot health check failures for Amazon ECS tasks on Fargate?

Deregistration errors can occur when a task fails the Elastic Load Balancing (ELB) health checks, and you receive one of the following errors:

  • "(service AWS-service) (port 8080) is unhealthy in (target-group arn:aws:elasticloadbalancing:us-east-1:111111111111:targetgroup/aws-targetgroup/123456789) due to (reason Health checks failed with these codes: [5xx]/[4xx]/[3xx]) or (Request timed out)."
  • "(service AWS-Service) (task eaa3ec9e9f104070b461490987654321) failed container health checks."
  • "(service AWS-Service) (instance 10.122.144.145) (port 8080) is unhealthy in (target-group arn:aws:elasticloadbalancing:ap-south-1:120987654321:targetgroup/AWS-Service-TG/159c835dc9d8cf84) due to (reason Target is in an Availability Zone that is not enabled for the load balancer)."

You might also receive the following error in the Amazon ECS console:

"Task failed ELB health checks in (target-group arn:aws:elasticloadbalancing:us-east-1:111111111111:targetgroup/aws-targetgroup/123456789)"

To resolve this issue, make sure that the endpoint that you configured in the target group health check is accurate.

If your Amazon ECS tasks are slow to respond to health checks, then it's a best practice to increase the value of the healthCheckGracePeriodSeconds parameter. Also, use slow start mode to allow targets to warm up before the load balancer sends them the health check requests.

Check your task and service configuration

Check the CPU and memory metrics for your service. High resource usage can make your application unresponsive and result in a 5xx error. To resolve these issues for tasks with both Fargate and Amazon EC2 launch types, see How can I monitor high memory utilization for Amazon ECS tasks on Fargate?

Verify that the task's elastic network interface or container instance security groups allow traffic from your load balancer on your network mode's required ports:

  • For awsvpc network mode, allow the port that you defined as containerPort in your task definition.
  • For bridge network mode, allow the ephemeral ports (32768-60999).

Related information

Amazon ECS stopped tasks error messages

Use an Application Load Balancer for Amazon ECS

Logging and monitoring in Amazon Elastic Container Service

AWS OFFICIALUpdated 2 years ago