How can I invoke a Lambda function within a Lambda function?
for example,
in function 1, it will be triggered by an API Gateway request and will invoke a second lambda function as an event (InvocationType = Event).
in function 2, it will do an http request to an endpoint.
also, am I going to code in serverless.yml? or code only on index/app/handler.js?
I tried the link here on stackoverflow -> Nodejs - Invoke an AWS.Lambda function from within another lambda function but it's not working.
var AWS = require('aws-sdk');
AWS.config.region = 'eu-west-1';
var lambda = new AWS.Lambda();
//LAMBDA A
exports.handler = function(event, context) {
var params = {
FunctionName: 'Lambda_B', // the lambda function we are going to invoke
InvocationType: 'RequestResponse',
LogType: 'Tail',
Payload: '{ "name" : "Yza" }'
};
lambda.invoke(params, function(err, data) {
if (err) {
context.fail(err);
} else {
context.succeed('Lambda_B said '+ data.Payload);
}
})
};
//LAMBDA B
exports.handler = function(event, context) {
console.log('Lambda B Received event:', JSON.stringify(event, null, 2));
context.succeed('Hello ' + event.name);
};