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