I'm using NestJS to create a microservice, hosted on AWS Lambda.
lambda.ts:
async function bootstrap(): Promise<INestApplicationContext> {
if (!cachedApp) {
cachedApp = await NestFactory.createMicroservice(AppModule);
cachedApp.init();
// cachedApp.listen() is a NO GO since we're in a serverless lambda!
}
return cachedApp;
}
export const sqsHandler = async (event, context: Context) => {
const instance = await bootstrap();
// How can I parse the 'event' to the instance??
};```
The function sqsHandler is triggered every time an event is push to a SQS queue.
How can I parse the lambda event to the nestjs microservice instance and get the result?
Lots of examples online shows how to use the NestFactory.createMicroservice with listen(), this is not a solution since this code is executed in a serverless AWS Lambda.
Also, using a stand-alone nestjs app is also not an option, since we need to implement a custom transport strategy.