79650902

Date: 2025-06-03 08:46:40
Score: 1.5
Natty:
Report link

Since my index file was in root directory, the problem was with handler function. As @Vigen mentioned in the comment, the package I was using was deprecated, use https://github.com/CodeGenieApp/serverless-express?tab=readme-ov-file#async-setup-lambda-handler

Here are the changes I made to my handler function in index file

let serverlessExpressInstance

const app = require("./express-app");

const StartServer = async (event, context) => {
  await databaseConnection();

  serverlessExpressInstance = serverlessExpress({ app })
  return serverlessExpressInstance(event, context)
  
};

function handler (event, context) {
  if (serverlessExpressInstance) return serverlessExpressInstance(event, context)

  return StartServer(event, context)
}

exports.handler = handler
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • User mentioned (1): @Vigen
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Arshdeep Singh