How can I customize my log files in Elastic Beanstalk?

Lesedauer: 2 Minute
1

I want to customize my log files in AWS Elastic Beanstalk, and stream my custom application logs to Amazon CloudWatch.

Short description

To customize your log files, complete the following steps:

  • Include your custom logs in the log bundle.
  • Rotate your logs.
  • (Optional) Stream your logs to CloudWatch.

Note: If you have a custom log file or a missing log from the default logs, then you can further customize your log configuration.

Resolution

Include your custom logs in the log bundle

When you request logs from Elastic Beanstalk, Elastic Beanstalk returns default log files from the Amazon Elastic Compute Cloud (Amazon EC2) instances in your environment. However, if your application has a unique log location, then you might not receive these default log files.

To get Elastic Beanstalk to return your log files from a unique log location, extend the default log task configuration.

Rotate your logs

Rotate your old log files with log rotation so that your application log files don't exhaust or take up too much disk space. When you rotate your logs, the old logs are automatically deleted from your environment's EC2 instances. To keep the old logs, upload the rotated logs to Amazon Simple Storage Service (Amazon S3) before the logs are deleted from the instance.

(Optional) Stream your logs to CloudWatch

In production applications, it's a best practice to stream your logs to a remote storage solution, such as CloudWatch. To turn on log streaming on Elastic Beanstalk, see Streaming log files to Amazon CloudWatch Logs or Using Elastic Beanstalk with Amazon CloudWatch Logs.

To stream custom log locations, see Instance log streaming using configuration files.

When you stream your logs to CloudWatch, you safeguard your data. For example, if your Elastic Beanstalk environment has an issue with an EC2 instance that terminates, then you can recover your logs from CloudWatch. You can also use log rotation to protect against data loss.

Related Information

What Is Amazon CloudWatch Logs?

Troubleshooting CloudWatch Logs integration

Streaming Elastic Beanstalk environment health information to Amazon CloudWatch Logs

AWS OFFICIAL
AWS OFFICIALAktualisiert vor 6 Monaten
2 Kommentare

If we want to customize the logs from instance for Amazon Linux 2 platform when the application is deployed using elasticbeanstalk, we need to follow these steps:

  1. Create a custom file in .ebextension/ in the root directory of your application
  2. Copy the below script and save the file with any name but with .config extension For Eg: custom-logs.config The below code is to include /var/log/messages logs to be streamed to cloudwatch ( can't paste the script here as its lengthy)

https://github.com/awsdocs/elastic-beanstalk-samples/blob/main/configuration-files/aws- provided/instance-configuration/logs-streamtocloudwatch-linux.config

  1. Deploy the application.

You should see the logs in cloudwatch for the configured logs.

beantwortet vor 7 Monaten

Thank you for your comment. We'll review and update the Knowledge Center article as needed.

profile pictureAWS
MODERATOR
beantwortet vor 7 Monaten