I need to call aws lambda from another lambda asynchronously. I have a working code for synchronous calls.
exports.handler = (event, context, callback) => { var aws = require('aws-sdk'); var lambda = new aws.Lambda({ region: 'myregion' //change to your region }); console.log("lambda invoke started"); lambda.invoke({ FunctionName: 'testLambda', Payload: JSON.stringify(event, null, 2) // pass params }, function (error, data) { if (error) { console.log("error"); callback(null, 'hello world'); } else { console.log("lambda invoke end"); callback(null, 'hello world'); } }); }
But in my case, "testLambda" is a function of time. Because I need to exit immediately after calling the testLambda function. Then the code is updated as follows
exports.handler = (event, context, callback) => { var aws = require('aws-sdk'); var lambda = new aws.Lambda({ region: 'myregion' //change to your region }); console.log("lambda invoke started"); lambda.invoke({ FunctionName: 'testLambda', Payload: JSON.stringify(event, null, 2) // pass params }); console.log("lambda invoke end"); callback(null, 'hello world'); }
it returns the message correctly. But my testLambda function is not called (no cloud observation logs are created for the test lambda). what is the problem with this code.
Abdul manaf
source share