question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CloudWatch LogGroups Not Getting Created

See original GitHub issue

My lambda function is not attached to any VPC, Still It is not posting logs to cloudwatch.

Here is my code.

 var exports = (module.exports = {});

const winston = require('winston');
const { createLogger, transports, format, error } = require('winston');
const WinstonCloudwatch = require('winston-cloudwatch');
const loggerFormat = format.combine(
  format.errors({ stack: true }),
  format.timestamp(),
  format.metadata(),
  format.json()
)

const consoleFormat = {
  format: format.combine(
    format.splat(),
    format.simple(),
    format.errors({ stack: true })
  ),
  level: 'info',
  handleExceptions: true,
  json: false,
  colorize: true
}
      let S3StreamLogger = require('s3-streamlogger-daily').S3StreamLogger;
    let date = new Date().toISOString().split('T')[0];
    let s3_stream_access = new S3StreamLogger({
      bucket: process.env.LOG_BUCKET,
      folder: userID,
      rotate_every: 'day',
      name_format: '%Y-%m-%d-%H-%M-keylogs.log'
    });
const logger = winston.createLogger({
  level: 'info',
  format: loggerFormat,
  transports: [
    //
    // - Write to all logs with level `info` and below to `combined.log` 
    // - Write all logs error (and below) to `error.log`.
    //
    new transports.Stream({
                stream: s3_stream_access,
                level: 'error'
              }),
    new WinstonCloudwatch({
          logGroupName: 'stepp-application-logs',
          exitOnError: false,
          logStreamName: `${date}/test`,
          createLogGroup: true,
          createLogStream: true,
          awsAccessKeyId : process.env.AWS_ACCESS_KEY_ID,
          awsSecretKey: process.env.AWS_SECRET_ACCESS_KEY,
          awsRegion: process.env.AWS_REGION,
          jsonMessage: false,
          awsOptions: {
            logStreamName: process.env.AWS_REGION
          },
          retentionInDays: 365,
          errorHandler: (err) => {
            console.log(err);
          },
          level: 'info'
        }),
    new winston.transports.Console(consoleFormat)
  ]
})

winston.add(logger)
winston.debug('Hey man, I am here!')

exports.logger = logger; 
```

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
lazywithclasscommented, Sep 8, 2020

Ok I see. I will close this ticket then, unless you’re willing to give more details, because this module is working on AWS Lambda for other users.

2reactions
arcsoftechcommented, Aug 28, 2020

No. It did not work. I had to use this package “winston-aws-cloudwatch” to make it work.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why isn't the unified CloudWatch agent pushing log events?
If there's no log group or log stream, the CloudWatch agent creates them. Add any missing IAM permissions to the user policy or...
Read more >
CloudWatch Log Group not automagically created #38 - GitHub
There's a small problem I'm having when using the module: The CloudWatch Log Group is only created when the Lambda Function tries to...
Read more >
AWS CloudWatch - Log group does not exist - Stack Overflow
1 Answer 1 · The AWS Region specified in the Amazon Resource Name (ARN) is the same as your Lambda function's Region. ·...
Read more >
How do I fix "Log group does not exist" errors for Lambda ...
How do I fix " Log group does not exist" errors for Lambda function logs in the CloudWatch console?
Read more >
Lambda logging to CloudWatch seems to be broken?
I tried creating the group manually, but now I'm back where I was -- the lambda runs, I get local log output, but...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found