How to deploy express app on api gateway?

0

I have deployed many times an express js app on api gateway. I use serverless-http module to wrap my express app so that it could be run on aws lambda and then api gateway.

But I noticed that today there has been slightly changes in the api gateway interface, that when I set up and deployed new api, it keeps returning internal server error everytime I wanted to access the routes i set up on the express app. Do you how to fix this issue?

Here's the code snippet to give you the insight to my express app:

import express from 'express';
import cors from 'cors';
import serverless from 'serverless-http';
import cookieParser from 'cookie-parser';

import { logger } from './utils/morganConfig.js';
import { securedHeader } from './utils/securedHeader.js';
import { userRoute, jobRoute, loginRoute, resetRoute, logoutRoute } from './routes/index.js';
const app = express();
app.use(logger);
app.use(securedHeader);
app.use(express.json());
app.use(cookieParser());
app.use(cors());

//routes
app.use('/users', userRoute);

console.log(">>> fixing api gateway...");
export const handler = serverless(app);

FYI I can rule out there shouldn't be any issue with the lambda setting, since any log before line export const handler = serverless(app); can still be logged in the cloudwatch console.

  • Not sure about serverless-http. I'm using AWS Lambda Web Adapter for same use case which does not introduce any code change for Express application.

Gracia
preguntada hace 7 meses119 visualizaciones
No hay respuestas

No has iniciado sesión. Iniciar sesión para publicar una respuesta.

Una buena respuesta responde claramente a la pregunta, proporciona comentarios constructivos y fomenta el crecimiento profesional en la persona que hace la pregunta.

Pautas para responder preguntas