Is It Possible to Have Centralised Logging for Elasticbeanstalk Docker Apps?

Better Stack Team
Updated on November 18, 2024

Yes, it is possible to implement centralized logging for Docker applications running on AWS Elastic Beanstalk. Centralized logging helps in monitoring and troubleshooting by aggregating logs from multiple instances into a single location for easier access and analysis. Here’s how to set up centralized logging for Elastic Beanstalk Docker applications.

Steps to Implement Centralized Logging

Step 1: Choose a Centralized Logging Solution

Common centralized logging solutions include:

  • Amazon CloudWatch Logs: A fully managed service that allows you to store, monitor, and access log files.
  • Elasticsearch, Logstash, and Kibana (ELK Stack): A popular open-source stack for searching, analyzing, and visualizing log data in real time.
  • Third-Party Services: Services like Splunk, Loggly, or Sumo Logic.

This guide will focus on using Amazon CloudWatch Logs and the ELK Stack.


Option 1: Using Amazon CloudWatch Logs

  1. Enable Logging in Elastic Beanstalk:
    • Go to the Elastic Beanstalk console.
    • Navigate to your application and environment.
    • In the "Configuration" section, under the "Software" category, ensure that the LOGGING option is enabled. This option allows you to send logs to CloudWatch.
  2. Modify Your Dockerfile:

    • Ensure your application logs to standard output (stdout) or standard error (stderr), as Elastic Beanstalk captures these logs automatically.
    • Example of logging in a Node.js application:

       
      console.log("This is a log message");
      
  3. Configure Log Groups:

    • CloudWatch automatically creates log groups for your environment. You can view and configure these in the CloudWatch Logs console.
    • Optionally, you can create custom log groups and configure your Elastic Beanstalk environment to push logs to these groups.
  4. Access Logs:

    • Navigate to the CloudWatch Logs console to view your logs. You can create filters and set alarms based on log patterns.

Option 2: Using the ELK Stack

If you prefer to use the ELK stack, follow these steps:

  1. Set Up an Elasticsearch Cluster:
    • Deploy an Elasticsearch cluster on AWS using Amazon Elasticsearch Service (now OpenSearch Service) or on EC2 instances.
  2. Deploy Logstash:
    • Deploy a Logstash instance (or use the ELK stack hosted on a single EC2 instance).
    • Configure Logstash to receive logs from your Docker applications.
  3. Modify Your Dockerfile:
    • Ensure your application logs to stdout/stderr as mentioned earlier.
  4. Install and Configure Filebeat:

    • Filebeat is a lightweight shipper for forwarding logs to Logstash or Elasticsearch.
    • Deploy Filebeat in your Elastic Beanstalk environment by including it in your Dockerfile or as a sidecar container.

    Sample Filebeat Configuration:

     
    filebeat.inputs:
      - type: docker
        containers.ids:
          - '*'
        json.keys_under_root: true
        json.add_error_key: true
    
    output.logstash:
      hosts: ["logstash:5044"]  # Update with your Logstash host
    
    
  5. Configure Logstash:

    • Create a Logstash configuration file to handle incoming logs from Filebeat and send them to Elasticsearch.
     
    input {
      beats {
        port => 5044
      }
    }
    
    output {
      elasticsearch {
        hosts => ["<http://elasticsearch:9200>"]  # Update with your Elasticsearch host
        index => "docker-logs-%{+YYYY.MM.dd}"
      }
    }
    
    
  6. Access Kibana:

    • Deploy Kibana to visualize and analyze logs stored in Elasticsearch.
    • Connect Kibana to your Elasticsearch instance to create visualizations and dashboards.

Conclusion

Centralized logging for Docker applications in AWS Elastic Beanstalk is achievable using Amazon CloudWatch Logs or the ELK stack. Both solutions provide effective ways to collect, store, and analyze logs from your applications, making it easier to monitor application performance and troubleshoot issues. Choose the method that best suits your architecture and operational needs.

Got an article suggestion? Let us know
Explore more
Licensed under CC-BY-NC-SA

This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Make your mark

Join the writer's program

Are you a developer and love writing and sharing your knowledge with the world? Join our guest writing program and get paid for writing amazing technical guides. We'll get them to the right readers that will appreciate them.

Write for us
Writer of the month
Marin Bezhanov
Marin is a software engineer and architect with a broad range of experience working...
Build on top of Better Stack

Write a script, app or project on top of Better Stack and share it with the world. Make a public repository and share it with us at our email.

community@betterstack.com

or submit a pull request and help us build better products for everyone.

See the full list of amazing projects on github