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

Last updated: 2022-07-22

When running a task in Amazon Elastic Container Service (Amazon ECS), I receive the following error:"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". How do I resolve the error?

Short description

Amazon ECS returns a ResourceInitialization error when the Amazon ECS task can't find the Amazon CloudWatch log group defined in the task definition. To resolve the error, create a new log group for the task.

Resolution

To resolve the ResourceInitialization error, choose one of these solutions to create a new log group for the task.

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 left navigation pane, choose Logs and then select Log groups.
  4. In the Log groups window, select Create log group.

Create a CloudWatch log group using AWS CLI

Create a CloudWatch log group using 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 Amazon ECS

The auto-configure option in the Amazon ECS console creates a log group on your behalf using the task definition family name with ecs as the prefix. The following example specifies a Log Configuration in your Task Definition.

{
  "containerDefinitions": [
    {
      "logConfiguration": {
        "logDriver": "awslogs",
         "options": {
           "awslogs-group": "/ecs/task_definition_familyname ",
           "awslogs-region": "eu-west-1",
           "awslogs-stream-prefix": "ecs"
    }
  }
}

You can also create a custom log group by specifying log configuration options and adding the key awslogs-create-group with a value of true to create the log groups on your behalf.

The following example specifies a Log Configuration in your Task Definition with option set.

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

Note: Managed AWS Identity and Access Management (IAM) policy AmazonECSTaskExecutionRolePolicy does not include logs:CreateLogGroup permissions. To use the awslogs-create-group option, add logs:CreateLogGroup as an inline IAM policy.


Did this article help?


Do you need billing or technical support?