Execute lambdas using express as api gateway
npm install lombdaThe 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.
``bash`
npm i lombda
If you have environment variables
`bash`
npm i dotenv.env
and create an file with your variables
`javascript
// 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,
});
`
You can add to your config
`javascript`
{
basePath: __dirname,
...,
cors: {
'Access-Control-Allow-Origin': string,
'Access-Control-Allow-Headers': string,
'Access-Control-Allow-Methods': string,
}
}
To run it just execute
`bash``
node lombda.js