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.

回答なし

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ