How to set Lambda Context in express js app which are deployed using Claudia

239 views Asked by At

I have an API server developed using express framework and now I am using Claudia to deploy them to AWS Lambda. Everything is going good and deployed.

New version of Claudia sets the callbackWaitsForEmptyEventLoop=false and this is exiting my APIs after a response is sent. I am doing some tasks like sending notifications and emails after response is sent and now these tasks are not being executed.

I am unable to find how to set params in lambda context using Claudia to reset the above flag. Is it possible at all?

Basically, I followed the below link to port an existing express app into AWS lambda using claudia.

https://claudiajs.com/tutorials/serverless-express.html

App deployed well except that I want to reset that flag in lambda context which I cannot do it from express app.

const express = require('express');
const app = express();

app.get('/events/number/:number/value', async (request, response) => {

    response.json(request.params);
    console.log('start: ', new Date());
    await wait(1000);
    console.log('end: ', new Date());
});

As soon as the response.json is called, start date is logged but lambda doesnt wait till the 'wait' promise is executed. It is executed and end date is logged in the next function call.

0

There are 0 answers