I have the following Promise.all
example.
Is the promise wrapper necessary with lambda.invoke
?
Referenced this thread
function get1(id) {
return new Promise((resolve, reject) => {
const params = {
FunctionName: 'myLambda', // the lambda function we are going to invoke
InvocationType: 'RequestResponse',
Payload: { id },
};
lambda.invoke(params, (err, data) => {
if (err) {
reject(new Error('error'));
} else {
const result = JSON.parse(data.Payload);
resolve(result);
}
});
}).catch(e => Promise.resolve({ error: 'Error has occurred.' }));
}
exports.getDetails = list => Promise.all(list.map(get1))
.then((response) => {
return result;
}).catch((error) => {
console.log('oops ', error);
});