Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-serverless-express NPM package will be deprecated in favor of @vendia/serverless-express #1045

Closed
tktwong opened this issue Oct 28, 2021 · 0 comments · Fixed by #1046
Closed

Comments

@tktwong
Copy link

tktwong commented Oct 28, 2021

proposed changes:

  1. adopt @vendia/serverless-express
npm uninstall @types/aws-serverless-express
npm uninstall aws-serverless-express
npm i --save @vendia/serverless-express
  1. index.ts
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { ExpressAdapter } from '@nestjs/platform-express';
import serverlessExpress from '@vendia/serverless-express';
import { APIGatewayProxyHandler, Handler } from 'aws-lambda';
import express from 'express';
import { AppModule } from './app.module';

let cachedServer: Handler;

const bootstrapServer = async (): Promise<Handler> => {
	const expressApp = express();
	const app = await NestFactory.create(AppModule, new ExpressAdapter(expressApp));
	app.useGlobalPipes(new ValidationPipe({ forbidUnknownValues: true }));
	app.enableCors();
	await app.init();
	return serverlessExpress({
		app: expressApp
	});
};

export const handler: APIGatewayProxyHandler = async (event, context, callback) => {
	if (!cachedServer) {
		cachedServer = await bootstrapServer();
	}
	return cachedServer(event, context, callback);
};
@hardyscc hardyscc linked a pull request Oct 28, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants