UNPKG

ts-lambda-local-dev

Version:
54 lines 2.4 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lambda_group_1 = require("../lambda.group"); // handler is a function that takes in an event and context and returns a response const handler = async (req, context) => { var _a; return ({ statusCode: 200, body: `Hello World !!! My userId is ${(_a = req.pathParameters) === null || _a === void 0 ? void 0 : _a.id}\n My JWT is ${JSON.stringify(req.requestContext.authorizer.lambda.jwt)}. My queryStringParameter is ${JSON.stringify(req.queryStringParameters)} ` }); }; const funnyHandler = async (req, context) => { var _a; return ({ statusCode: 200, body: `Hello World !!! I'm funny and my userId is ${(_a = req.pathParameters) === null || _a === void 0 ? void 0 : _a.id}\n My JWT is ${JSON.stringify(req.requestContext.authorizer.lambda.jwt)}. My queryStringParameter is ${JSON.stringify(req.queryStringParameters)} ` }); }; // context is provided as optional field in config. const config = [ { handler: handler, requestContext: { authorizer: { lambda: { jwt: { claims: { sub: '1234567890', name: 'John Doe', iat: 1516239022, }, scopes: ['read', 'write'], }, }, }, }, pathParamsPattern: '/user/:id', // optional, default to '/' }, { handler: funnyHandler, pathParamsPattern: '/user/:id/funny', requestContext: { authorizer: { lambda: { jwt: { claims: { sub: '1234567890', name: 'John Doe', iat: 1516239022, }, scopes: ['read', 'write'], }, }, }, }, }, ]; const multiConfig = { lambdas: config, port: 8008, defaultPath: '/api/v1', // optional, default to '/' }; // visit http://localhost:8008/api/v1/user/1234567890 and http://localhost:8008/api/v1/user/1234567890/funny to see the response const localLambdaGroup = new lambda_group_1.LocalLambdaGroup(multiConfig); localLambdaGroup.run(); //# sourceMappingURL=multi.js.map