Rupesh Agrawal
Rupesh Agrawal

Reputation: 31

Enable logging to Cloudwatch of the tomcat log files of Elastic Bean Stalk

I am farely new to the AWS environment, and trying to configure the logs produced by the tomcat instance eunninging enside an AWS ElasticBeanstalk, to Cloudwatch. I tried configuring it from the ElasticBeanstalk console, and all I can see is the below list of files, I don't see the logs like "catalina.2018-08-16.log", "localhost_access_log.txt", "catalina.out" etc, what do I need to do to see them as well?

List of log files available on Cloudwatch

Upvotes: 2

Views: 3229

Answers (3)

RobbiewOnline
RobbiewOnline

Reputation: 1370

I've detailed in a new Medium blog how this all works and an example .ebextensions file and where to put it.

Below is an excerpt that you might be able to use, though the article explains how to determine the right folder/file(s) to stream.

packages:
  yum:
    awslogs: []

option_settings:
  - namespace: aws:elasticbeanstalk:cloudwatch:logs
    option_name: StreamLogs
    value: true
  - namespace: aws:elasticbeanstalk:cloudwatch:logs
    option_name: DeleteOnTerminate
    value: false
  - namespace: aws:elasticbeanstalk:cloudwatch:logs
    option_name: RetentionInDays
    value: 90

files:
  "/etc/awslogs/awscli.conf" :
    mode: "000600"
    owner: root
    group: root
    content: |
      [plugins]
      cwlogs = cwlogs
      [default]
      region = `{"Ref":"AWS::Region"}`

  "/etc/awslogs/config/logs.conf" :
    mode: "000600"
    owner: root
    group: root
    content: |
      [/var/log/tomcat/localhost.log]
      log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/tomcat/localhost.log"]]}`
      log_stream_name = {instance_id}
      file = /var/log/tomcat/localhost.*

      [/var/log/tomcat/catalina.log]
      log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/tomcat/catalina.log"]]}`
      log_stream_name = {instance_id}
      file = /var/log/tomcat/catalina.*

      [/var/log/tomcat/localhost_access_log.txt]
      log_group_name = `{"Fn::Join":["/", ["/aws/elasticbeanstalk", { "Ref":"AWSEBEnvironmentName" }, "var/log/tomcat/access_log"]]}`
      log_stream_name = {instance_id}
      file = /var/log/tomcat/access_log.*

commands:
  "01":
    command: systemctl enable awslogsd.service
  "02":
    command: systemctl restart awslogsd

Upvotes: 0

Rupesh Agrawal
Rupesh Agrawal

Reputation: 31

I was able to do that by following the instructions closely on the page https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.cloudwatchlogs.html , section "Instance Log Streaming Using Configuration Files"

We need to put a config file to tell the cloudwatch agent to pick what all files I want. And configure the appropriate permissions by attaching appropriate policy, to the EC2 role, so that it can operate on cloudwatch .

Upvotes: 1

Gustavo Tavares
Gustavo Tavares

Reputation: 2805

There is a think with Elastic Beanstalk logs that requires some explanation to you understand what is happening. Elastic Beanstalk is the PaaS offer from AWS (Platform as a Service). They provide a entire platform for you, limited to a few options (Node.Js, Python, PHP, Tomcat, etc..). In a birds view, all the platforms are composed by:

  1. An endpoint for static content (apache, nginx);
  2. An "application server" where you can deploy your app;
  3. Load balancer, Analytics (X-Ray) and other options, depending of your configuration;
  4. A database instance if you configure at environment creation;

This are comom things for all platforms, doesn't matter if it is Node.JS, tomcat or others. The logs of this components are streamed to CloudWatch.

The logs specific for the platform that you choose are not streamed to CloudWatch. They stay in the instance(s) that are managed by Elastic Beanstalk. If you need to see this logs you can get access to it using the Elastic Beanstalk console. In the console, go to the left pane, select the option "Logs". There you will find instructions to download the logs (entire or just the last 100 lines).

You also can configure Elastic Beanstalk to deploy this logs, but not to CloudWatch. They are delivered to the S3 Bucket that you choose on configuration.

Upvotes: 1

Related Questions