awsdocs / aws-elastic-beanstalk-developer-guide

The open source version of the AWS Elastic Beanstalk Developer Guide. You can submit feedback and requests for changes by submitting issues in this repo or by making proposed changes and submitting a pull request.
https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/Welcome.html
Other
199 stars 195 forks source link

Add updated custom CloudWatch logs integration guide #150

Closed hdodov closed 1 year ago

hdodov commented 1 year ago

I followed the Elastic Beanstalk custom CloudWatch logs documentation, but stumbled into permissions errors. I've laid the issues out in great detail in my Stack Overflow question.

The problem is that the Elastic Beanstalk docs encourage the usage of the CloudWatch Logs agent, but it states the following:

This reference is for the older deprecated CloudWatch Logs agent. If you use Instance Metadata Service Version 2 (IMDSv2), you must use the new unified CloudWatch agent. Even if you are not using IMDSv2, we strongly recommend that you use the newer unified CloudWatch agent instead of the older logs agent.

I was able to create a new configuration file that sets up Elastic Beanstalk to use the new CloudWatch agent. You can check my Stack Overflow answer, but here's the gist of it:

.ebextensions/custom-cloudwatch-logs.config

container_commands:
  01_append_logs_config:
    command: |
      amazon-cloudwatch-agent-ctl -a append-config -m ec2 -c file:/tmp/custom-cloudwatch-config.json -s

files:
  "/tmp/custom-cloudwatch-config.json":
    mode: "000600"
    owner: root
    group: root
    content: |
      {
        "logs": {
          "logs_collected": {
            "files": {
              "collect_list": [
                {
                  "file_path": "/var/log/php-fpm/www-error.log",
                  "log_group_name": "/aws/elasticbeanstalk/Project-env/var/log/php-fpm/www-error.log",
                  "log_stream_name": "{instance_id}"
                }
              ]
            }
          }
        }
      }

The official Elastic Beanstalk docs should provide a solution that revolves around this new approach, rather than the outdated CloudWatch Logs agent.

joshbean commented 1 year ago

Closing this issue or pull request in advance of archiving this repo. For more information about the decision to archive this repo (and others in the 'awsdocs' org), see the announcement on the AWS News Blog.