I am trying to write a lambda function that triggers many small lambdas
exports.handler = (event, context, callback) => {
var AWS = require('aws-sdk');
let noOfPages = 20, currentPage = 1;
var message = '';
//let payloadArray = [];
while(currentPage <= noOfPages){
message = '{"first_page": '+ currentPage +', "last_page": '+ (currentPage) + ', "file_name" : "something.doc"' +'}';
console.log(message);
var params = {
FunctionName: 'test',
InvocationType: 'Event',
LogType: 'Tail',
Payload: message
};
var convLambda = new AWS.Lambda({
accessKeyId: 'key',
secretAccessKey: 'secret',
region: 'us-west-2'
});
convLambda.invoke(params, function(err, data) {
if (err) {
context.fail(err);
} else {
context.succeed('Processed : '+ data);
}
})
currentPage+=1;
}
};
This works well and triggers, say 20 lambdas. I would however, like to wait till all the async lambdas are done (fork and join). Is there way to achieve this currently in Amazon Lambda?