serverless-lambda-router
![Build Status](https://travis-ci.org/swhite24/serverless-lambda-router.svg?branch=master)
serverless-lambda-router is a router framework to be used within a single lambda function supporting an API Gateway stage. Note that this library requires a lambda runtime of 6.10
.
serverless-lambda-router operates around promises, so use of async / await with babel is encouraged. To deliver a response, resolve the handler with the payload. To deliver an error, throw the Boom error.
Originally developed for use with the serverless framework.
Installation
npm install --save serverless-lambda-router
Usage
const Boom = require('boom');
const LambdaRouter = require('serverless-lambda-router');
const router = new LambdaRouter({
headers: {
'Cache-Control': 'max-age=0, private, no-cache, no-store'
},
onInvoke: event => {},
onError: (err, event) => {}
});
router.get('/foo', async (event, context) => {
return {
foo: 'bar'
};
});
router.get('/bar', async (event, context) => {
throw Boom.notFound('Resource not found');
});
router.get('/baz', async (event, context) => {
context.state.name = 'John Smith';
}, async (event, context) => {
return {
name: context.state.name
};
});
exports.handler = router.handler();