npm install @serverless-framework/aws-lambda
AWS Lambda with Node.js
import { RequestInterface, ResponseInterface, HttpStatusCode } from '@serverless-framework/core'; import { Api } from '@serverless-framework/aws-lambda'; import { APIGatewayProxyEvent, APIGatewayProxyEventV2, Context } from 'aws-lambda'; const API_VERSION = '1.0.0'; const api = new Api({ base: '/api', }); api.get('/version', (req: RequestInterface, res: ResponseInterface) => { req.status(HttpStatusCode.OK).json({ version: API_VERSION, }); }); export const handler = api.handle((event: APIGatewayProxyEvent | APIGatewayProxyEventV2, context: Context) => await api.run());
api.get('/users/:id', (req: RequestInterface<{params: {id: string}}>, res: ResponseInterface) => { req.status(HttpStatusCode.OK).json({ id: params.id, }); });
Next: Learn more about routing.