DockerLogsToAwsCloudWatchLogGroups

nicolaw 4th January 2022 at 6:51pm
Docker

Global default

/etc/docker/daemon.json:

{
  "log-driver": "awslogs",
  "log-opts": {
    "awslogs-region": "eu-west-2"
  }
}

Docker compose

myservice:
  logging:
    driver: awslogs
    options:
      awslogs-region: eu-west-2

Explicit invocation

docker run \
    --log-driver=awslogs \
    --log-opt awslogs-region=eu-west-2 \
    --log-opt awslogs-group=myLogGroup \
    --log-opt awslogs-stream=myContainerNameOrOmitForContainerId \
    --log-opt awslogs-create-group=true \

AWS IAM policy

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Action": [
        "logs:CreateLogStream",
        "logs:CreateLogGroup",
        "logs:PutLogEvents"
      ],
      "Effect": "Allow",
      "Resource": "arn:${Partition}:logs:${Region}:${Account}:log-group:${LogGroupName}/*"
    }
  ]
}