Karolis Stulgys
04/26/2022, 8:47 AMKarolis Stulgys
04/26/2022, 8:48 AMKarolis Stulgys
04/26/2022, 8:49 AMimport { NestFactory } from '@nestjs/core';
import serverlessExpress from '@vendia/serverless-express';
import { Handler } from 'aws-lambda';
import { AppModule } from './app.module';
export async function bootstrap(): Promise<Handler> {
const app = await NestFactory.create(AppModule);
await app.init();
const expressApp = app.getHttpAdapter().getInstance();
return serverlessExpress({ app: expressApp });
}
Karolis Stulgys
04/26/2022, 8:50 AMimport { APIGatewayProxyHandlerV2 } from "aws-lambda";
import { Handler } from "aws-lambda";
import { bootstrap } from "../../server/src/main";
let server: Handler;
export const handler: APIGatewayProxyHandlerV2 = async (
event,
context,
callback
) => {
server = server ?? (await bootstrap());
return server(event, context, callback);
};
Karolis Stulgys
04/26/2022, 9:46 AMKarolis Stulgys
04/26/2022, 12:35 PMKarolis Stulgys
04/26/2022, 3:28 PMexport default class MyStack extends sst.Stack {
constructor(scope, id, props) {
super(scope, id, props);
const api = new sst.Api(this, "Api", {
routes: {
$default: {
function: {
handler: "src/lambda.handler",
bundle: {
externalModules: [
"class-validator",
"class-transformer",
"@nestjs/websockets/socket-module",
"@nestjs/microservices/microservices-module",
"cache-manager",
"@nestjs/microservices",
],
},
},
},
},
});
this.addOutputs({
ApiEndpoint: api.url,
});
}
}
Frank
Frank
externalModules
imported on the fly by nestjs? It seems esbuild didn’t bundle them by default.Frank