################################################################################################### #### Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. #### #### Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file #### except in compliance with the License. A copy of the License is located at #### #### http://aws.amazon.com/apache2.0/ #### #### or in the "license" file accompanying this file. This file is distributed on an "AS IS" #### BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the #### License for the specific language governing permissions and limitations under the License. ################################################################################################### ################################################################################################### #### The following file configures the AWS CloudWatch agent to push logs to a Log Group in CloudWatch Logs. #### #### The configuration below sets the logs to be pushed, the Log Group name to push the logs to, #### the Log Stream name as the instance id, and the log retention period. #### This example streams /var/log/messages, but you can modify it stream other files. #### `retention_in_days` is optional. #### #### Find more information about configuring the CloudWatch agent here: #### https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html #### #### You can then access the CloudWatch Logs by accessing the AWS CloudWatch Console and clicking #### the "Logs" link on the left. The Log Group name will follow this format: #### #### /aws/elasticbeanstalk// #### #### Please note this configuration should be used additionally to the "Log Streaming" feature: #### http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.cloudwatchlogs.html ################################################################################################### files: "/opt/aws/amazon-cloudwatch-agent/etc/my_log_config.json": mode: "0644" owner: root group: root content: | { "logs": { "logs_collected": { "files": { "collect_list": [ { "file_path": "/var/log/messages", "log_group_name": "`{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/messages"]]}`", "log_stream_name": "{instance_id}", "retention_in_days": 7 } ] } } } } container_commands: 01_append_cloudwatch_agent_config: command: /opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent-ctl -a append-config -s -c file:/opt/aws/amazon-cloudwatch-agent/etc/my_log_config.json 02_remove_backup_file: command: rm -f /opt/aws/amazon-cloudwatch-agent/etc/my_log_config.json.bak ignoreErrors: true