callback is not working..
Closed this issue · 2 comments
`
var winston = require('winston'),
WinstonCloudWatch = require('winston-cloudwatch');
exports.handler = (event, context, callback) => {
winston.add(WinstonCloudWatch, {
logGroupName: 'testing',
logStreamName: 'first'
});
var error = new Error('we are doooooomed!');
winston.error('error', error)
callback(null, "success")
};
`
The callback is not working, Lambda just shows the time out error, What is the solution of thiss issue ???
thanks & regards
What are you trying to achieve? I am not sure what you mean with "Lambda just shows the time out error", are you saying you're running this into AWS Lambda and getting a timeout, what's your use case?
I slightly changed this code and run it as so
var winston = require('winston'),
WinstonCloudWatch = require('winston-cloudwatch');
handler = (event, context, callback) => {
winston.add(WinstonCloudWatch, {
logGroupName: 'testing',
logStreamName: 'first'
});
var error = new Error('we are doooooomed!');
winston.error('error', error)
callback(null, "success")
};
handler(null, null, () => console.log('hello'))
which prints
error: error Error: we are doooooomed!
at handler (/private/tmp/tmp.js:9:14)
at Object. (/private/tmp/tmp.js:17:1)
at Module._compile (module.js:624:30)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Function.Module.runMain (module.js:665:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:607:3
hello
I need more informations from your side if you need help with this issue.
Hi @lazywithclass I'm having this similar issue, getting timeout error in aws lambda. would be able to check what's wrong
logger.js file
const winston = require('winston'),
WinstonCloudWatch = require('winston-cloudwatch');
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
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");
}
};