lambda-lambda-lambda

AWS Lambda@Edge serverless application router.

Features
- Routes and URI resource support.
- Local/Globally scoped middleware.
- Request/Response handling API.
- Lightweight/cost effective solution.
Dependencies
Installation
Install package dependencies using NPM.
$ npm install lambda-lambda-lambda
Usage
Lambda function
'use strict';
const Router = require('lambda-lambda-lambda');
exports.handler = (event, context, callback) => {
const {request, response} = event.Records[0].cf;
const router = new Router(request, response);
router.setPrefix('/api');
router.use(function(req, res, next) {
if (req.method() === 'CONNECT') {
res.status(405).send();
} else {
next();
}
});
router.get('/', function(req, res) {
res.status(501).send();
});
router.default(function(req, res) {
res.status(404).send();
});
callback(null, router.response());
};
Route handler
'use strict';
const contentTypeHeader = require('middleware/ContentTypeHeader');
module.exports = {
middleware: [contentTypeHeader],
index (req, res) {
res.status(200).send('Lambda, Lambda, Lambda');
},
create (req, res) {
res.status(201).send();
},
update (req, res) {
res.status(204).send();
},
delete (req, res) {
res.status(410).send();
},
submit (req, res) {
res.status(200).send();
}
};
Resource handler
'use strict';
module.exports = {
resource: true,
index (req, res, id) {
res.setHeader('Content-Type', 'application/json');
res.status(200).json({and: 'Omega Mu'});
},
create (req, res, id) {
res.status(201).send();
},
update (req, res, id) {
res.status(204).send();
},
delete (req, res, id) {
res.status(410).send();
},
submit (req, res, id) {
res.status(200).send();
}
};
Mixed Route/Resource handler
'use strict';
module.exports = {
resource: ['index'],
index (req, res, id) {
res.setHeader('Content-Type', 'application/json');
res.status(200).json({and: 'Omega Mu'});
},
create (req, res) {
res.status(201).send();
},
update (req, res) {
res.status(204).send();
},
delete (req, res) {
res.status(410).send();
},
submit (req, res) {
res.status(200).send();
}
};
Middleware
'use strict';
module.exports = (req, res, next) => {
res.setHeader('Content-Type', 'text/html');
next();
};
App Example
A deployable application has been provided with this package. In order to successfully deploy you must have set-up your AWS Config and have created an IAM user with the following policies:
WARNING: The policies above are provided to ensure a successful application deployment. It is recommended that you adjust these policies to meet the security requirements of your Lambda application. They should NOT be used in a Production environment.
Developers
CLI options
Run ESLint on project sources:
$ npm run lint
Generate documentation using JSDoc:
$ npm run gendoc
Run Mocha integration tests:
$ npm run test
Contributions
If you fix a bug, or have a code you want to contribute, please send a pull-request with your changes. (Note: Before committing your code please ensure that you are following the Node.js style guide)
Versioning
This package is maintained under the Semantic Versioning guidelines.
License and Warranty
This package is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
lambda-lambda-lambda is provided under the terms of the MIT license
AWS is a registered trademark of Amazon Web Services, Inc.
Author
Marc S. Brooks