aws lambda request timeout error using winston-cloudwatch for logging

Viewed 18

I'm getting "Endpoint request timed out" error on AWS Lambda when using winston-cloudwatch 6.1.1 for logging. below is my code. logs are getting saved in cloudwatch in AWS and on local it's also working fine, but only on server it's throwing error.

logger.js file

const logger = winston.createLogger({
  format: winston.format.json(),
  transports: [
    new winston.transports.Console({
      timestamp: true,
      colorize: true,
      level: "info",
      format: winston.format.combine(
        winston.format.colorize({ message: true })
      ),
    }),
  ],
});

let self = logger.add(
  new WinstonCloudWatch({
    name: "log",
    logGroupName: "EventLog",
    logStreamName: "Stream",
    createLogGroup: true,
    createLogStream: true,
    awsOptions: {
      region: xxxxx,
      credentials: {
        accessKeyId: xxxxx,
        secretAccessKey: xxxxxx,
      },
    },
    messageFormatter: ({ level, message, response }) => {
      return `[${level}] : ${message} : ${JSON.stringify(response)}`;
    },
  })
);

let transport = self.transports.find((t) => t.name === "log");
transport.kthxbye(() => console.log("flushed"));

index.js file

const cloudwatch = require("./logger");

module.exports.someFunction = async (event, context, callback) => {
  try {
    let result = await xyz();
    cloudwatch.logger.log("info", "-", { response: result });
    callback(null, result);
  } catch (err) {
    console.log("catch");
  }
};
0 Answers
Related