15

My Elastic Beanstalk environment is stopping streaming node.js events to CloudWatch Logs. Streaming works fine for a view minutes on a new instance. After a view minutes no more logs show up in CloudWatch.

I set up AWS Elastic Beanstalk to stream logs to CloudWatch under Configuration > Software Configuration > CloudWatch Logs > Log Streaming (true). I deactivated log streaming and reactivated it as a test. Taking a look at cloudwatch

  • Last eb-activity log is about 10 minutes old
  • Error log is not available (on neither of the instances)
  • nginx/access.log is a view seconds old
  • nodejs.log is about an hour old (short after relaunching instance)

Every health check writes an log entry every view seconds into nodejs.log though.

I did not find any logs on the ec2 instance regarding log streaming.

  1. Has anyone similar issues?
  2. How do I make Elastic Beanstalk stream nodejs logs to CloudWatch logs.

--- EDIT

[ec2-user@ip-###-##-##-## log]$ cat /var/log/awslogs.log 
2017-03-07 11:01:05,928 - cwlogs.push.stream - INFO - 31861 - Thread-1 - Detected file rotation, notifying reader
2017-03-07 11:01:05,928 - cwlogs.push.stream - INFO - 31861 - Thread-1 - Reader is still alive.
2017-03-07 11:01:05,928 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/error.log*'.
2017-03-07 11:01:05,928 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/access.log*'.
2017-03-07 11:01:06,052 - cwlogs.push.reader - INFO - 31861 - Thread-8 - No data is left. Reader is leaving.
2017-03-07 11:01:10,929 - cwlogs.push.stream - INFO - 31861 - Thread-1 - Removing dead reader [2177a5cce5ed29525de329bfdc292ff1, /var/log/nginx/access.log]
2017-03-07 11:01:10,929 - cwlogs.push.stream - INFO - 31861 - Thread-1 - Starting reader for [92257964a10edeb586f084f4f2ba35de, /var/log/nginx/access.log]
2017-03-07 11:01:10,930 - cwlogs.push.reader - INFO - 31861 - Thread-11 - Start reading file from 0.
2017-03-07 11:01:10,930 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/error.log*'.
2017-03-07 11:01:10,930 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/access.log*'.
2017-03-07 11:01:15,931 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/error.log*'.
2017-03-07 11:01:15,931 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/access.log*'.
2017-03-07 11:01:16,788 - cwlogs.push.publisher - INFO - 31861 - Thread-7 - Log group: /aws/elasticbeanstalk/production/var/log/nginx/access.log, log stream: i-0bd24767864801e2c, queue size: 0, Publish batch: {'skipped_events_count': 0, 'first_event': {'timestamp': 1488884470930, 'start_position': 0L, 'end_position': 114L}, 'fallback_events_count': 0, 'last_event': {'timestamp': 1488884472931, 'start_position': 341L, 'end_position': 454L}, 'source_id': '92257964a10edeb586f084f4f2ba35de', 'num_of_events': 4, 'batch_size_in_bytes': 554}
2017-03-07 11:01:20,932 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/error.log*'.
2017-03-07 11:01:20,932 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/access.log*'.
2017-03-07 11:01:25,933 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/error.log*'.
2017-03-07 11:01:25,933 - cwlogs.push.stream - WARNING - 31861 - Thread-1 - No file is found with given path '/var/log/httpd/access.log*'.
2017-03-07 11:01:27,881 - cwlogs.push.publisher - INFO - 31861 - Thread-7 - Log group: /aws/elasticbeanstalk/production/var/log/nginx/access.log, log stream: i-0bd24767864801e2c, queue size: 0, Publish batch: {'skipped_events_count': 0, 'first_event': {'timestamp': 1488884481933, 'start_position': 454L, 'end_position': 568L}, 'fallback_events_count': 0, 'last_event': {'timestamp': 1488884482934, 'start_position': 568L, 'end_position': 681L}, 'source_id': '92257964a10edeb586f084f4f2ba35de', 'num_of_events': 2, 'batch_size_in_bytes': 277}
Manuel
  • 9,112
  • 13
  • 70
  • 110
  • 1
    check `/var/log/awslogs.log` file for errors and ensure that the awslogs service is running – b.b3rn4rd Mar 07 '17 at 11:03
  • @b.b3rn4rd: found it, however this file does never mention nodejs logs nor any problem regarding it. – Manuel Mar 07 '17 at 11:08
  • its mentioned in the doco – b.b3rn4rd Mar 07 '17 at 11:08
  • I guess you refer to http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/AWSHowTo.cloudwatchlogs.html? I tried to check configs, but could not find eb-logs.config or any other of the configs described on that page anywhere on the ec2 instance. – Manuel Mar 07 '17 at 11:23
  • there is no error in the /var/log/awslogs.log. While the first two log rotations cycles (2hours) of awslogs.log the nodejs.logs ar published to the cloudwatch logs. The third los file does not contain any nodejs logs any more. No error at all. – Manuel Mar 07 '17 at 12:37
  • Did you ever find an answer to this? I am having exactly the same issue. – Si-N Mar 16 '18 at 11:58
  • Nope. Unlucky not – Manuel Mar 16 '18 at 19:16
  • Jun 2018 - I recently tested this with the nodejs sample app for elastic beanstalk. Disabled streaming via the config per the OP and verified log streaming stopped in the cloudwatch logs console. Then re-enabled streaming and log streaming resumed just fine. I recommend we close this question because the issue is not reproduceable. – Taterhead Jun 12 '18 at 14:38
  • I am facing exactly the same issue with Docker based deployment. – Prabu Nov 21 '18 at 16:24
  • facing exact same issue, anyone was able to sort it ou? – Affan Shahab May 12 '20 at 21:15

3 Answers3

1

When Andrew (@andrew-ferk) and myself activated log streaming, it created all the log groups and streams in CloudWatch with the current log. After we deployed again, we noticed the logs stopped. This is because aws hashes the first line of the log. If it has seen that hash before it will treat that file like it's already been processed

If you are using npm start the first lines will be your application's name with version.

You can add a CMD date && npm start to your dockerfile to trigger a different first line each time or run npm in silent mode (as long as your first output is unique).

Also according to their docs you should add some policy to your elastic-beanstalk before enabling the feature AWS-Docs

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:GetLogEvents",
        "logs:PutLogEvents",
        "logs:DescribeLogGroups",
        "logs:DescribeLogStreams",
        "logs:PutRetentionPolicy"
      ],
      "Resource": [
        "*"
      ]
    }
  ]
}
Partyless
  • 121
  • 1
  • 9
1

The following FAQs might be helpful:

Some things to check if you are streaming custom log files:

  1. eb ssh into the instance and look at /var/log/awslogs.log. If that doesn't even mention "Loading additional configs from (your awslogs config file)", make sure you are installing your config file correct as well as restarting the awslogs service after installing it (presumably using .ebextensions. See "Custom Log File Streaming" in Using Elastic Beanstalk with Amazon CloudWatch Logs. See the commands section in logs-streamtocloudwatch-linux.config for how to restart the awslogs service.
  2. The CloudWatch Logs Agent is stateful. If the first few lines of your log file are blank or never change, you may need to set file_fingerprint_lines. See CloudWatch Logs Agent Reference.
jrc
  • 20,354
  • 10
  • 69
  • 64
0

If you have a Apache, Then you need to use /var/log/httpd/error_log as the error log target and you can ignore /var/log/nginx unless you use nginx.

First, check the aws Cloudwatch agent is installed or not on the your machine using
sudo service awslogs status

If you have amazon liunx 2 use systemctl status awslogsd
If aws Cloudwatch agent is not Install. then use the below script
.ebextension customizes file_fingerprint_lines for apache
create an .ebextension file with name 02_logs.config and use the code

packages:
  yum:
    awslogs: []

files:
  "/etc/awslogs/config/beanstalklogs.conf":
    mode: "000644"
    user: root
    group: root
    content: |
      file_fingerprint_lines=2-5

      [/var/log/httpd/error_log]
      log_group_name=/aws/elasticbeanstalk/your-env/var/log/httpd/error_log
      log_stream_name={instance_id}
      file=/var/log/httpd/error_log*
 
      [/var/log/httpd/access_log]
      log_group_name=/aws/elasticbeanstalk/your-env/var/log/httpd/access_log
      log_stream_name={instance_id}
      file=/var/log/httpd/access_log*
 
      [/var/log/eb-activity.log]
      log_group_name=/aws/elasticbeanstalk/your-env/var/log/eb-activity.log
      log_stream_name={instance_id}
      file=/var/log/eb-activity.log*

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

Now check on Cloud watch it will stream the logs if you have any issue you can check the aws Cloudwatch agent logs.