How do I resolve the "ResourceInitializationError: failed to validate logger args" error in Amazon ECS?

4 minute read
0

When I run a task in Amazon Elastic Container Service (Amazon ECS), I receive a "ResourceInitializationError: failed to validate logger args" error.

Short description

When an Amazon ECS task can't find the Amazon CloudWatch log group that's defined in the task definitionAmazon, Amazon ECS returns a ResourceInitialization error. You receive the following error message:

"ResourceInitializationError: failed to validate logger args: create stream has been retried 1 times: failed to create CloudWatch log stream: ResourceNotFoundException: The specified log group does not exist. : exit status 1"

To resolve the error, create a new log group for the task.

To troubleshoot the errors for Amazon ECS tasks that fail to start, use the AWSSupport-TroubleshootECSTaskFailedToStart runbook. Then, refer to the relevant troubleshooting steps for your issue.

Resolution

Find a task that failed to start

Important:

  • Use the AWSSupport-TroubleshootECSTaskFailedToStart runbook in the same AWS Region where your ECS cluster resources are located.
  • When using the runbook, you must use the most recently failed Task ID. If the failed task is part of an Amazon ECS service, then use the most recently failed task in the service. The failed task must be visible in ECS:DescribeTasks during the automation. By default, stopped ECS tasks are visible for 1 hour after entering the Stopped state. Using the most recently failed task ID prevents the task state cleanup from interrupting the analysis during the automation.

For instructions on how to initiate the runbook, see AWSSupport-TroubleshootECSTaskFailedToStart. Based on the output of the automation, use one of the following manual troubleshooting steps.

Troubleshoot the error

To resolve the ResourceInitialization error, review the following solutions to create a new log group for the task.

If you don't know which log group is defined in the task definition and returning an error, then run the following command:

aws ecs describe-task-definition --task-definition nginx-fargate:3 | jq -r .taskDefinition.containerDefinitions[].logConfiguration

The output describes the log group that you must recreate in CloudWatch.

Create a CloudWatch log group in the console

  1. Open the CloudWatch console.
  2. From the navigation bar, choose the Region where Amazon ECS cluster is located.
  3. In the navigation pane, choose Logs, and then choose Log groups.
  4. In the Log groups window, choose Create log group.

Create a CloudWatch log group using AWS CLI

Create a CloudWatch log group with the create-log-group AWS Command Line Interface (AWS CLI) command. The following example command creates a log group named mylogs:

Note: If you receive errors when running AWS CLI commands, make sure that you're using the most recent version of the AWS CLI.

aws logs create-log-group --log-group-name mylogs

Use the auto-configuration feature in the Amazon ECS console

The auto-configure option uses the task definition family name with ecs as the prefix to create a log group for you. The following example specifies a log configuration in your task definition:

{  "containerDefinitions": [  
    {  
      "logConfiguration": {  
        "logDriver": "awslogs",  
        "options": {  
          "awslogs-create-group": "true",  
          "awslogs-group": "awslogs-wordpress",  
          "awslogs-region": "us-west-2",  
          "awslogs-stream-prefix": "awslogs-example"  
        }  
      }  
    }  
  ]  
}

You can also create a custom log group with the following steps:

  1. Specify log configuration options.
  2. Add the key awslogs-create-group with a value of true. This creates the log group for you.

The following example specifies a log configuration in your task definition with options set:

{  "containerDefinitions": [  
    {  
      "logConfiguration": {  
        "logDriver": "awslogs",  
        "options": {  
          "awslogs-group": "example_container",  
          "awslogs-region": "eu-west-1",  
          "awslogs-create-group": "true",  
          "awslogs-stream-prefix": "example"  
        }  
      }  
    }  
  ]  
}

Note: The managed AWS Identity and Access Management (IAM) policy AmazonECSTaskExecutionRolePolicy doesn't include logs:CreateLogGroup permissions. To use the awslogs-create-group option, add logs:CreateLogGroup as an inline IAM policy.