Reputation: 2027
lets say I have this lambda function:
exports.handler = (event, context, callback) => {
lambda.invoke({
FunctionName: 'longCheckout',
InvocationType: 'Event',
Payload: JSON.stringify(event, null, 2) // pass params
}, function(error, data) {
console.log(error, data)
callback(null, data);
});
};
and I want to call the longCheckout lambda that will do some work and send back a response to the invoking lambda and then continue to execute a longer request. So the lambda function I am calling has a callback argument but when I call that passed in function, nothing happens in the invoking lambda. Here is what the lambda I am calling looks like
exports.handler = (event, test, callback) => {
docClient.update(params, function(err, data) {
callback(....)
// continue to execute
})
}
Upvotes: 1
Views: 551
Reputation: 1953
Lambda can be invoked synchronously (the default behavior that you used), or asynchronously. If you will choose to invoke asynchronously, both lambdas will continue running at the same time, but you won't be able to get any return value.
A possible solution to do what you ask for is:
docClient.update
and invokes asynchronously Lambda 3 (then returns).Read this about asynchronous invocations.
Upvotes: 1