Elastic Beanstalk Docker with Amazon CloudWatch Elastic Beanstalk Docker with Amazon CloudWatch docker docker

Elastic Beanstalk Docker with Amazon CloudWatch


I've just encountered the same issue - I managed to get the log files by changing the LogFile configuration to

Mappings:  CWLogs:    WebRequestLogGroup:      LogFile: "/var/log/eb-docker/containers/eb-current-app/*.log"      TimestampFormat: "%d/%b/%Y:%H:%M:%S %z"

Note this only works if there is a single log file, if you re-deploy a container or apply a configuration change which results in multiple logs in this directory then only the events from the log file with the most current modified time will be processed by the awslogs agent

Also by default the agent will compare the first line of the log file to determine if it is a different file, if the first line is the same it will ignore it. You can specify the lines the agent uses to fingerprint the file by adding file_fingerprint_lines configuration,

for example to use lines 1 - 20 to identify the file:

AWSEBAutoScalingGroup:    Metadata:      "AWS::CloudFormation::Init":        CWLogsAgentConfigSetup:          files:            ## any .conf file put into /tmp/cwlogs/conf.d will be added to the cwlogs config (see cwl-agent.config)            "/tmp/cwlogs/conf.d/apache-access.conf":              content : |            [    apache-access_log]                file = `{"Fn::FindInMap":["CWLogs", "WebRequestLogGroup", "LogFile"]}`                log_group_name = `{ "Ref" : "AWSEBCloudWatchLogs8832c8d3f1a54c238a40e36f31ef55a0WebRequestLogGroup" }`                file_fingerprint_lines = 1-20                log_stream_name = {instance_id}                datetime_format = `{"Fn::FindInMap":["CWLogs", "WebRequestLogGroup", "TimestampFormat"]}`              mode  : "000400"              owner : root              group : root


I create Dockerrun file for each ElasticBeanstalk application. https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/create_deploy_docker_image.html

There you can specify a logging configuration:

           "logConfiguration": {                "logDriver": "awslogs",                "options": {                    "awslogs-group": "${you-log-group-name}",                    "awslogs-region": "${region}",                    "awslogs-stream-prefix": "${serviceName}"                }            }

This sets up Docker's logging driver configurationmore details:https://docs.docker.com/config/containers/logging/configure/


This is now possible in Amazon Linux 2's docker platform using docker-compose.yaml:

version: '3.8'services:  your-service:    logging:      driver: awslogs      options:        awslogs-group: "${your-log-group-name}"        awslogs-region: "us-west-2"

See here for more options:https://docs.docker.com/config/containers/logging/awslogs/