Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS EB Node.JS Log to CloudWatch

is there any possible solution to stream Node.JS log of application running on Elastic Beanstalk to Amazon CloudWatch?

I did saw cwl-webrequest-metrics.config file but with no information about it's format I can not format it to stream Node.JS log (only) to CloudWatch.

That you in advance for your comments!

like image 920
Alexey Avatar asked Aug 28 '15 11:08

Alexey


People also ask

How do I get EB logs?

Open the Elastic Beanstalk console , and in the Regions list, select your AWS Region. In the navigation pane, choose Environments, and then choose the name of your environment from the list. If you have many environments, use the search bar to filter the environment list. In the navigation pane, choose Logs.

How do I convert Elasticsearch to CloudWatch logs?

Go to the AWS CloudWatch console and click on Logs at the left most; select the CloudTrail Log group that we just created earlier, and click on Actions and select Stream to Amazon Elasticsearch Service.

Where is AWS EB engine log?

/aws/elasticbeanstalk/myapp-myenv/var/log/eb-engine. log.


1 Answers

Question's a little old, but for those of you coming from Google, here's a working .ebextension config for Node.JS log streaming into cloudwatch:

# Store Node.JS Application Logs in Cloudwatch
Mappings:
  CWLogs:
    NodeJSLogGroup:
      LogFile: "/var/log/nodejs/nodejs.log"
      TimestampFormat: "%d/%b/%Y:%H:%M:%S %z"

Outputs:
  NodeJSCWLogGroup:
    Description: "Node.JS Application Logs"
    Value: { "Ref" : "AWSEBCloudWatchLogs8832c8d3f1a54c238a40e36f31ef55a0NodeJSLogGroup"}


Resources :
  AWSEBCloudWatchLogs8832c8d3f1a54c238a40e36f31ef55a0NodeJSLogGroup:    ## Must have prefix:  AWSEBCloudWatchLogs8832c8d3f1a54c238a40e36f31ef55a0
    Type: "AWS::Logs::LogGroup"
    DependsOn: AWSEBBeanstalkMetadata
    DeletionPolicy: Retain     ## this is required
    Properties:
      LogGroupName:
        "Fn::GetOptionSetting":
          Namespace: "aws:elasticbeanstalk:application:environment"
          OptionName: NodeJSCWLogGroup
          DefaultValue: {"Fn::Join":["-", [{ "Ref":"AWSEBEnvironmentName" }, "nodejs"]]}
      RetentionInDays: 14


  ## Register the files/log groups for monitoring
  AWSEBAutoScalingGroup:
    Metadata:
      "AWS::CloudFormation::Init":
        CWLogsAgentConfigSetup:
          files:
            ## any .conf file put into /tmp/cwlogs/conf.d will be added to the cwlogs config (see cwl-agent.config)
            "/tmp/cwlogs/conf.d/nodejs.conf":
              content : |
                [nodjs-log]
                file = `{"Fn::FindInMap":["CWLogs", "NodeJSLogGroup", "LogFile"]}`
                log_group_name = `{ "Ref" : "AWSEBCloudWatchLogs8832c8d3f1a54c238a40e36f31ef55a0NodeJSLogGroup" }`
                log_stream_name = {instance_id}
                datetime_format = `{"Fn::FindInMap":["CWLogs", "NodeJSLogGroup", "TimestampFormat"]}`
              mode  : "000400"
              owner : root
              group : root

Looks like http://serebrov.github.io/html/2015-05-20-cloudwatch-setup.html might be a good reference as well.

like image 97
Ben Hayden Avatar answered Oct 04 '22 16:10

Ben Hayden