ECS Action Logs now has additional logging targets, so I checked the events of Fargate tasks

ECS Action Logs now has additional logging targets, so I checked the events of Fargate tasks

I tested Amazon ECS Action Logs task events on Fargate. Image pull failures, abnormal container exits, and container health check failures were logged under separate event names, and exit codes appeared in detail.containers[].exitCode.
2026.11.23

This page has been translated by machine translation. View original

Introduction

On November 20, 2026, Amazon ECS Action Logs added support for logging tasks, container instances, clusters, and capacity providers.

https://aws.amazon.com/about-aws/whats-new/2026/11/amazon-ecs-action-logs-expanded-troubleshooting/

Action Logs is a feature that delivers time-stamped records of operations that ECS performs automatically, such as pulling images, registering with load balancers, and stopping tasks, to destinations such as CloudWatch Logs. In this article, I check the events related to Fargate tasks.

Test Environment

  • Region: Tokyo (ap-northeast-1)
  • Launch type: Fargate (platform version not specified)
  • Network: public subnet, with a public IP assigned
  • AWS CLI: 2.42.1
  • Cluster: newly created ala-verify

Enabling Action Logs

Configuring delivery

I created a cluster and a log group, then enabled Action Logs with three commands: delivery source, delivery destination, and delivery. I named the log group /aws/vendedlogs/ecs/action-logs/<cluster name>, the same as the default when enabling it in the console, and set the retention period to 7 days.

aws ecs create-cluster --cluster-name ala-verify

aws logs create-log-group --log-group-name /aws/vendedlogs/ecs/action-logs/ala-verify
aws logs put-retention-policy --log-group-name /aws/vendedlogs/ecs/action-logs/ala-verify --retention-in-days 7

aws logs put-delivery-source --name ala-verify-source \
  --resource-arn arn:aws:ecs:ap-northeast-1:<account-id>:cluster/ala-verify \
  --log-type ACTION_LOGS

aws logs put-delivery-destination --name ala-verify-dest --output-format json \
  --delivery-destination-configuration '{"destinationResourceArn": "arn:aws:logs:ap-northeast-1:<account-id>:log-group:/aws/vendedlogs/ecs/action-logs/ala-verify"}'

aws logs create-delivery --delivery-source-name ala-verify-source \
  --delivery-destination-arn arn:aws:logs:ap-northeast-1:<account-id>:delivery-destination:ala-verify-dest

All three commands succeeded in the Tokyo Region.

Retrieving the logs

I retrieved the logs with filter-log-events and formatted each message to read it.

aws logs filter-log-events \
  --log-group-name /aws/vendedlogs/ecs/action-logs/ala-verify \
  --query 'events[].message' --output json \
  | python3 -c 'import sys,json; [print(json.dumps(json.loads(m),indent=2)) for m in json.load(sys.stdin)]'

The top-level fields in the logs I retrieved were these five: resourceArn, actionSourceId, logLevel, eventTimestamp, and detail. The event name was in detail.eventName.

The log stream name was the same as actionSourceId.

Task Events

Image pull failure

I prepared a task definition that specifies an image with a tag that does not exist.

taskdef-pullfail.json
{
  "family": "ala-pullfail",
  "requiresCompatibilities": ["FARGATE"],
  "networkMode": "awsvpc",
  "cpu": "256",
  "memory": "512",
  "executionRoleArn": "arn:aws:iam::<account-id>:role/ecsTaskExecutionRole",
  "containerDefinitions": [
    {
      "name": "app",
      "image": "public.ecr.aws/nginx/nginx:does-not-exist",
      "essential": true,
      "command": ["nginx","-g","daemon off;"]
    }
  ]
}

I registered it and ran it with run-task.

aws ecs register-task-definition --cli-input-json file://taskdef-pullfail.json

aws ecs run-task --cluster ala-verify --launch-type FARGATE --task-definition ala-pullfail \
  --network-configuration "awsvpcConfiguration={subnets=[<subnet-id>],securityGroups=[<security-group-id>],assignPublicIp=ENABLED}"

Here is the recorded TASK_FAILED_TO_START log.

{
  "resourceArn": "arn:aws:ecs:ap-northeast-1:111122223333:cluster/ala-verify",
  "actionSourceId": "cluster/ala-verify",
  "logLevel": "ERROR",
  "eventTimestamp": 1795275553592,
  "detail": {
    "statusReason": "CannotPullContainerError: pull image manifest has been retried 7 time(s): failed to resolve ref public.ecr.aws/nginx/nginx:does-not-exist: public.ecr.aws/nginx/nginx:does-not-exist: not found",
    "taskArn": "arn:aws:ecs:ap-northeast-1:111122223333:task/ala-verify/1234567890abcdef0",
    "stopCode": "TaskFailedToStart",
    "lastStatus": "PENDING",
    "eventName": "TASK_FAILED_TO_START"
  }
}

The reason for the startup failure was available in detail.statusReason. It took about 90 seconds from running run-task to this log's eventTimestamp.

Abnormal container exit

I prepared a task definition that waits 20 seconds and then exits with exit code 3.

taskdef-exit3.json
{
  "family": "ala-exit3",
  "requiresCompatibilities": ["FARGATE"],
  "networkMode": "awsvpc",
  "cpu": "256",
  "memory": "512",
  "executionRoleArn": "arn:aws:iam::<account-id>:role/ecsTaskExecutionRole",
  "containerDefinitions": [
    {
      "name": "app",
      "image": "public.ecr.aws/docker/library/busybox:latest",
      "essential": true,
      "command": ["sh","-c","sleep 20; exit 3"]
    }
  ]
}

I registered it and ran it with run-task.

aws ecs register-task-definition --cli-input-json file://taskdef-exit3.json

aws ecs run-task --cluster ala-verify --launch-type FARGATE --task-definition ala-exit3 \
  --network-configuration "awsvpcConfiguration={subnets=[<subnet-id>],securityGroups=[<security-group-id>],assignPublicIp=ENABLED}"

Here is the recorded TASK_STOPPED_UNEXPECTEDLY log.

{
  "resourceArn": "arn:aws:ecs:ap-northeast-1:111122223333:cluster/ala-verify",
  "actionSourceId": "cluster/ala-verify",
  "logLevel": "ERROR",
  "eventTimestamp": 1795275515672,
  "detail": {
    "statusReason": "Essential container in task exited",
    "taskArn": "arn:aws:ecs:ap-northeast-1:111122223333:task/ala-verify/1234567890abcdef0",
    "stopCode": "EssentialContainerExited",
    "lastStatus": "RUNNING",
    "containers": [
      {
        "name": "aws-guardduty-agent-4d23Dfm",
        "exitCode": 0
      },
      {
        "name": "app",
        "exitCode": 3
      }
    ],
    "eventName": "TASK_STOPPED_UNEXPECTEDLY"
  }
}

The exit code was in detail.containers[].exitCode.

The containers list also included the aws-guardduty-agent-* container (exitCode 0) that had been automatically added to the Fargate task.

Container health check failure

I prepared a task definition whose container health check always fails.

taskdef-unhealthy.json
{
  "family": "ala-unhealthy",
  "requiresCompatibilities": ["FARGATE"],
  "networkMode": "awsvpc",
  "cpu": "256",
  "memory": "512",
  "executionRoleArn": "arn:aws:iam::<account-id>:role/ecsTaskExecutionRole",
  "containerDefinitions": [
    {
      "name": "app",
      "image": "public.ecr.aws/docker/library/busybox:latest",
      "essential": true,
      "command": ["sh","-c","sleep 3600"],
      "healthCheck": {
        "command": ["CMD-SHELL", "exit 1"],
        "interval": 5,
        "timeout": 2,
        "retries": 2,
        "startPeriod": 0
      }
    }
  ]
}

I created a service with this task definition.

aws ecs register-task-definition --cli-input-json file://taskdef-unhealthy.json

aws ecs create-service --cluster ala-verify --service-name ala-unhealthy-svc \
  --task-definition ala-unhealthy --desired-count 1 --launch-type FARGATE \
  --network-configuration "awsvpcConfiguration={subnets=[<subnet-id>],securityGroups=[<security-group-id>],assignPublicIp=ENABLED}"

Here is the recorded TASK_STOPPED_UNHEALTHY log.

{
  "resourceArn": "arn:aws:ecs:ap-northeast-1:111122223333:cluster/ala-verify",
  "actionSourceId": "service/ala-verify/ala-unhealthy-svc",
  "logLevel": "ERROR",
  "eventTimestamp": 1795275593449,
  "detail": {
    "clusterArn": "arn:aws:ecs:ap-northeast-1:111122223333:cluster/ala-verify",
    "taskArn": "arn:aws:ecs:ap-northeast-1:111122223333:task/ala-verify/1234567890abcdef0",
    "stopCode": "ServiceSchedulerInitiated",
    "statusReason": "Task failed container health checks",
    "failureType": "CONTAINER_HEALTH_CHECK",
    "lastStatus": "RUNNING",
    "serviceRevisionArn": "arn:aws:ecs:ap-northeast-1:111122223333:service-revision/ala-verify/ala-unhealthy-svc/1234567890123456789",
    "unhealthyContainerNames": [
      "app"
    ],
    "eventName": "TASK_STOPPED_UNHEALTHY"
  }
}

The type of health check that failed was available in detail.failureType, and the failed container in detail.unhealthyContainerNames.

This event did not include an exit code. When I checked the same task with describe-tasks, the exitCode of app was 137.

Even for this service, whose health check always fails, SERVICE_REVISION_STABLE (INFO) was recorded with the status SUCCEEDED. TASK_STOPPED_UNHEALTHY appeared about 90 seconds after that (about 2 minutes after the service was created).

Summary

I confirmed that ECS Action Logs records Fargate task events.

Previously, Action Logs covered service deployments and managed daemon updates, but this update expands the scope.

If you want to investigate the causes of task startup failures or abnormal exits, enable Action Logs and make use of it.

Share this article

AWSのお困り事はクラスメソッドへ