Launching fire and forget events inside lambda handler

Hi,

Is it possible to launch fire and forget events inside a lambda function?
I’m using node.js and I’m wondering if the technique I used before using express.js it could work in lambda.
I mean this:

// code…

//Launch the function but don’t wait the callback and do other things…
fireAndForgetEvent(params, function(err, res) { console.log('fire and forget)});

// other things here…
db.findUser(userId, function(err, user){
console.log('the user:, user);
return lambdaHandlerCallback(err, user)
});

I suppose as soon as lambdaHandlerCallback is called Lambda should kill all code execution and maybe it does not work.
In that case, what should I do in order to launch logger or analytics functions that I don’t want to interrupt the core business code execution?

Thank you in advance

You can do this by calling another lambda function with the InvocatinoType = Event. It will invoke the other function without waiting for the response.

http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html#invoke-property

4 Likes

Just in case someone (like me) is looking for the way to trigger HTTP API method in “fire and forget” manner:
You can make node’s native https.request and wait for ‘end’ callback only,
to make sure the endpoint received you request,
but without waiting for response.
Here is an example for zeit/node v2 lambdas