2.0.12 • Published 8 months ago
lombda v2.0.12
Lombda
This is a POC that lets you simulate an api gateway lambda proxy integration using an alternative server framework. For the moment only Express.js is supported.
The library transforms the incoming request object to the payload that api gateway sends to the lambda when configured as Lambda Proxy Integration, more details can be found here. It also supports lambda authorizer.
Setup
Lombda requires that you define the routes that your lambdas will be mapped to. To start you must install lombda package.
npm i lombdaIf you have environment variables
npm i dotenvand create an .env file with your variables
// lombda.js
const dotenv = require('dotenv');
const Lombda = require('lombda').default;
dotenv.config();
Lombda.express([
{
lambdaIndex: 'path/to/public/lambda/dist/index.js',
lambdaHandler: 'handler',
routeKey: 'POST /public-lambda',
},
{
lambdaIndex: 'path/to/authorized/lambda/index.js',
lambdaHandler: 'handler',
routeKey: 'GET /authorized-lambda',
authorizer: {
lambdaIndex: 'path/to/authorizer/dist/index.js',
lambdaHandler: 'handler',
},
},
], {
basePath: __dirname,
port: 3002,
});CORS
You can add to your config
{
basePath: __dirname,
...,
cors: {
'Access-Control-Allow-Origin': string,
'Access-Control-Allow-Headers': string,
'Access-Control-Allow-Methods': string,
}
}To run it just execute
node lombda.js