How to Investigate Amazon ECS Task Stop Reason 'Essential container in task exited'

Tadashi Shigeoka ·  Sat, August 14, 2021

I’ll introduce how to check errors for Amazon ECS tasks that stopped with “Essential container in task exited”.

AWS

How to Check Errors for Stopped Tasks (AWS Management Console)

To check errors for stopped tasks (AWS Management Console)

Step 5: In the [Details] section, examine the [Stop reason] field to see why the task was stopped.

Essential container in task exited When a container marked as essential in the task definition exits or stops, the task may be stopped. If the task was stopped because an essential container exited, step 6 will provide detailed diagnostic information about what caused the container to stop.

Step 6: If there are stopped containers, expand the container and examine the [Status reason] line to see what caused the task state to change.

In the case of Essential container in task exited, if the [Status reason] shows [exitCode 0], no error has occurred, so there’s no problem.

How to Check Errors for Stopped Tasks (AWS CLI)

AWS_ECS_PROFILE="your-profile"
AWS_ECS_CLUSTER="your-cluster"

aws ecs list-tasks \\
  --profile $AWS_ECS_PROFILE \\
  --cluster $AWS_ECS_CLUSTER \\
  --desired-status STOPPED
aws ecs describe-tasks \\
  --profile $AWS_ECS_PROFILE \\
  --cluster $AWS_ECS_CLUSTER \\
  --tasks arn:aws:ecs:ap-northeast-1:account_id:task/cluster_name/task_ID

Let’s check the exitCode and stopCode.

That’s all from the Gemba on how to check errors for Amazon ECS tasks that stopped with “Essential container in task exited”.

Reference Information