How can i setup aws cloudwatch logs with docker ecs container How can i setup aws cloudwatch logs with docker ecs container docker docker

How can i setup aws cloudwatch logs with docker ecs container


In your task definition, specify the logging configuration as the following:

"logConfiguration": {  "logDriver": "awslogs",   "options": {    "awslogs-group": "LogGroup",    "awslogs-region": "us-east-1",    "awslogs-stream-prefix": "Prefix"  }}
  • awslogs-stream-prefix is optional for EC2 launch type but required for Fargate

In the UserData section when you launch a new instance, register the instance to the cluster and make sure you specify the logging of type awslogs as well:

#!/bin/bashecho 'ECS_CLUSTER=ClusterName' > /etc/ecs/ecs.configecho ECS_AVAILABLE_LOGGING_DRIVERS='[\"json-file\", \"awslogs\"]' >> /etc/ecs/ecs.configstart ecs

More Info:

https://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html


You have to do two things:

  1. Configure the ECS Task Definition to take logs from the container output and pipe them into a CloudWatch logs group/stream. To do this, you add a LogConfiguration property to each ContainerDefinition property in your ECS task definition. You can see the docs for this here, here, and here.
  2. Instead of writing logs to a file in the container, instead write them to /dev/stdio or /dev/stdout / /dev/stderr. You can just use these paths in your Apache configuration and you should see the Apache log messages outputted to the container's log.


You can use the awslogs logging driver of Docker

Refer to the documentation on how to set it uphttps://docs.aws.amazon.com/AmazonECS/latest/developerguide/using_awslogs.html