Learning center

ECS ResourceInitializationError: awslogs log group does not exist

Read the failed revision's awslogs-group, awslogs-region and awslogs-create-group, then look the group up in that Region. A missing group with awslogs-create-group unset means the reference or the group is wrong, a missing group with the option set points at the execution role's logs:CreateLogGroup permission, and a group that exists points at the network path from the task to CloudWatch Logs.

One reason, three causes#

A new deployment's tasks stop with stop code TaskFailedToStart and a stopped reason that begins ResourceInitializationError and concerns the awslogs log driver or its log group. The task has no startedAt, so the containers never ran and wrote nothing. AWS lists two causes for this reason: the log group in the task definition does not exist or is named wrongly, or the task cannot connect to CloudWatch Logs. Its page on stopped-reason wording maps the logger message to the same two causes. ResourceInitializationError troubleshooting · Stopped-task message updates

The missing-group cause splits in two once you read the revision, which gives three nearby causes:

  • The group does not exist where the driver looks. The revision names a group that was never created, was renamed, or exists in a different Region from awslogs-region.
  • The driver was asked to create the group and could not. awslogs-create-group is true, but the identity creating the group lacks logs:CreateLogGroup. The managed AmazonECSTaskExecutionRolePolicy grants logs:CreateLogStream and logs:PutLogEvents; AWS says the execution role (or, on EC2, the instance role) must also include logs:CreateLogGroup before you use the option.
  • The group exists, but the task cannot reach CloudWatch Logs. The task runs in a subnet with no route to the public endpoint and no interface endpoint for CloudWatch Logs.

awslogs options · Send ECS logs to CloudWatch · Task execution role

This is one row of the signature table. If the reason names Secrets Manager or Systems Manager instead, use the secrets guide.

Capture the failed task and its exact revision#

Use a read-only profile and replace the uppercase placeholders. ECS keeps stopped tasks for at least one hour, so save the output early. Stopped task retention

aws ecs list-tasks \
  --profile PROFILE --region REGION --cluster CLUSTER \
  --service-name SERVICE --desired-status STOPPED \
  --query 'taskArns' --output json --no-cli-pager

aws ecs describe-tasks \
  --profile PROFILE --region REGION --cluster CLUSTER --tasks TASK_ARN \
  --query 'tasks[].{task:taskArn,definition:taskDefinitionArn,deployment:startedBy,code:stopCode,reason:stoppedReason,started:startedAt,launch:launchType,platform:platformVersion,az:availabilityZone}' \
  --output json --no-cli-pager

Pass the full definition ARN to the next command; a family name alone resolves to the latest revision. The query lists each container's log driver and options, and the execution role that Fargate uses to write logs. Task fields

aws ecs describe-task-definition \
  --profile PROFILE --region REGION --task-definition TASK_DEFINITION_ARN \
  --query 'taskDefinition.{definition:taskDefinitionArn,executionRole:executionRoleArn,logs:containerDefinitions[].{container:name,driver:logConfiguration.logDriver,options:logConfiguration.options}}' \
  --output json --no-cli-pager

Look the group up where the driver writes#

Run the lookup in the Region from awslogs-region, which can differ from the cluster's Region, with a profile for the account the task runs in. awslogs-region lets you send logs from clusters in several Regions to one Region, and AWS asks you to make sure the group exists in the Region you name. awslogs options

aws logs describe-log-groups \
  --profile PROFILE --region AWSLOGS_REGION --log-group-name-prefix LOG_GROUP \
  --query 'logGroups[].{name:logGroupName,arn:arn,created:creationTime}' \
  --output json --no-cli-pager

The prefix filter also returns longer names, so look for an exact match. A group named /ecs/orders-api does not satisfy a revision that names /ecs/orders. describe-log-groups

What each result means#

Group in awslogs-regionawslogs-create-groupLikely causeNext read
MissingAbsent or falseThe revision names a group that does not exist thereCompare the name and Region with the previous revision's
MissingtrueThe execution role cannot create it, or the task cannot reach CloudWatch LogsThe role's permission, then the network path
PresentEitherThe task cannot reach CloudWatch LogsThe network path

Compare the failing revision's log options with the revision that last ran. If only awslogs-group or awslogs-region changed, the first row is the likely reading. If the log options are unchanged and the deployment moved to new subnets, start with the network path.

Check the role's permission to create the group#

With awslogs-create-group set to true, the role named in executionRole creates the group as the task starts. Simulate the call against that role. The simulator evaluates identity-based policies and the inputs you give it, and AWS notes that its results can differ from the live environment, so treat an allowed result as a lead. Option requirements · SimulatePrincipalPolicy

aws iam simulate-principal-policy \
  --profile PROFILE \
  --policy-source-arn EXECUTION_ROLE_ARN \
  --action-names logs:CreateLogGroup logs:CreateLogStream logs:PutLogEvents \
  --resource-arns 'arn:aws:logs:AWSLOGS_REGION:ACCOUNT_ID:log-group:LOG_GROUP:*' \
  --query 'EvaluationResults[].{action:EvalActionName,decision:EvalDecision}' \
  --output json --no-cli-pager

The stream actions are in the same call because the driver needs them for every task, whether or not it creates the group. An implicitDeny or explicitDeny on logs:CreateLogGroup matches the second row; an allowed result sends you on to the network path. The change is either to create the group yourself and drop the option, or to grant logs:CreateLogGroup on that group's ARN to the execution role. On EC2 without an execution role, the container instance role is the identity to check. Execution role policy

Check the network path to CloudWatch Logs#

On Fargate platform version 1.4.0 and later, all of a task's network traffic flows through the task's network interface in your subnet. If the VPC has no internet gateway and tasks use the awslogs driver, AWS says you must create an interface VPC endpoint for CloudWatch Logs, and the endpoint's security group must allow inbound TCP 443 from the tasks' subnets. A task in a private subnet can instead reach the public endpoint through a route to a NAT gateway. Fargate task networking · ECS interface endpoints · CloudWatch Logs endpoints

Read the subnets the failing deployment used, then the routes and endpoints those subnets have:

aws ecs describe-services \
  --profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
  --query 'services[0].deployments[].{id:id,definition:taskDefinition,subnets:networkConfiguration.awsvpcConfiguration.subnets,securityGroups:networkConfiguration.awsvpcConfiguration.securityGroups,publicIp:networkConfiguration.awsvpcConfiguration.assignPublicIp}' \
  --output json --no-cli-pager

aws ec2 describe-route-tables \
  --profile PROFILE --region REGION --filters Name=association.subnet-id,Values=SUBNET_ID \
  --query 'RouteTables[].Routes[].{destination:DestinationCidrBlock,nat:NatGatewayId,gateway:GatewayId,state:State}' \
  --output json --no-cli-pager

aws ec2 describe-vpc-endpoints \
  --profile PROFILE --region REGION --filters Name=service-name,Values=com.amazonaws.REGION.logs \
  --query 'VpcEndpoints[].{id:VpcEndpointId,state:State,subnets:SubnetIds,groups:Groups[].GroupId,privateDns:PrivateDnsEnabled}' \
  --output json --no-cli-pager

If describe-route-tables returns nothing, the subnet uses the VPC's main route table; filter on Name=vpc-id,Values=VPC_ID and Name=association.main,Values=true instead. A subnet with no default route through a NAT gateway or internet gateway, and no logs endpoint in its VPC, has no path to CloudWatch Logs. A route through an internet gateway also needs a public IP on a Fargate task, which publicIp shows. An endpoint in another Region does not help, since VPC endpoints do not support cross-Region requests. Route table fields · VPC endpoint fields · ECS interface endpoints

If other tasks from the same deployment stopped while pulling their image, the subnet's outbound path is the shared suspect; see image pull timeouts from a private subnet.

Two ways orders:58 can fail#

This fixture is illustrative and continues the hub's example. The fictional service orders moves from orders:57 to orders:58 in deployment ecs-svc/2211. Both revisions run on Fargate 1.4.0 in us-east-1. Tasks from the new deployment stop with TaskFailedToStart and a ResourceInitializationError reason that names the awslogs driver.

ReadMissing groupMissing permission
orders:57 log optionsawslogs-group /ecs/orders, region us-east-1awslogs-group /ecs/orders, region us-east-1
orders:58 log optionsawslogs-group /ecs/orders-api, no awslogs-create-groupawslogs-group /ecs/orders-api, awslogs-create-group true
describe-log-groups in us-east-1Only /ecs/ordersOnly /ecs/orders
simulate-principal-policy on logs:CreateLogGroupNot neededimplicitDeny
Network of ecs-svc/2211 vs ecs-svc/1987Same subnets and security groupsSame subnets and security groups

In the first case, orders:58 renamed the group and nothing created it. Either create /ecs/orders-api before the next deployment or point the revision back at /ecs/orders. In the second case, the revision asked the driver to create the group and the execution role, which carries only the managed policy, was denied. Granting logs:CreateLogGroup on that group's ARN or creating the group ahead of time both remove the denial. In both cases the subnets match the revision that worked, which makes the network path an unlikely cause.

Confirm on the replacement task#

After the change, record the new task's ARN, its exact revision and its startedAt. A replacement that reaches RUNNING with the same log options has passed log driver initialization. Then confirm that a stream exists. With awslogs-stream-prefix set, the stream name is the prefix, the container name and the task ID. Stream naming

aws logs describe-log-streams \
  --profile PROFILE --region AWSLOGS_REGION --log-group-name LOG_GROUP \
  --log-stream-name-prefix PREFIX/CONTAINER/TASK_ID \
  --query 'logStreams[].{stream:logStreamName,lastEvent:lastEventTimestamp}' \
  --output json --no-cli-pager

If you fixed a permission or created a group, the revision may not change at all. Note that in the incident record so the next reader does not look for a revision diff.

Where this reading stops#

AWS notes that stopped-reason text can change, so key automation on stopCode and keep the reason as evidence. The lookup answers whether the group exists now, not at the time the task stopped, so a group someone created during the incident hides the first cause. The simulator does not read every policy that applies to a live request, and a correct route table can still be undone by a network ACL or a security group that blocks outbound TCP 443. Stopped-task message updates · SimulatePrincipalPolicy

Bring the fix into the pull request#

The log group, the awslogs options and the execution role usually live in different files. Put the group's creation, or the role grant, in the same pull request as the revision that names the group, so a reviewer sees all three together. Proofline reviews GitHub pull requests; new organizations get one calendar month of hosted code review without a cloud connection. Start a free GitHub review · Eligibility and fair-use terms · Current product availability

Questions#

Why does an ECS task fail when the awslogs log group does not exist?

The awslogs driver writes to the group named in awslogs-group in the Region named in awslogs-region. When that group is missing, the task fails during resource initialization with ResourceInitializationError, before its containers run, so it leaves no application logs.

Does awslogs-create-group fix a missing log group?

It makes ECS create the group when the task starts, which works only if the execution role, or on EC2 the instance role, allows logs:CreateLogGroup. The managed AmazonECSTaskExecutionRolePolicy does not include that action.

Do Fargate tasks in a private subnet need a CloudWatch Logs endpoint?

They need a route to CloudWatch Logs. A NAT gateway provides one; in a VPC with no internet gateway, AWS says you must create an interface endpoint for CloudWatch Logs in the same Region.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading