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
已提問 7 個月前檢視次數 119 次
沒有答案

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南