AWS Lambda framework for building functions using Node.js for API Gateway, IoT applications, and other AWS events.
- Simplifies writing lambda handlers
- Automatically verifies event types
- Powerful input validation
- Works with Serverless
- JSON Web Token (JWT) verification and validation
- Cross Site Request Forgery (XSRF) detection when using JWT
- SQL Injection (SQLi) detection and protection
- Lambda Proxy Resource support for AWS API Gateway
- Post handler execution to allow deallocation of resources
- Forces values into correct types
- Handles uncaught exceptions
- Promise support
- Automatically trimmed strings for input event data
- Low startup overhead
- AWS Lambda Node.js 6.10.x compatible
Install via npm.
npm install vandium --save
Vandium creates event specific handlers to reduce the amount of code than one needs to maintain. Vandium will automatically detect and validate that the event is intended for the target service. For example, creating a handler for S3 events:
const vandium = require( 'vandium' );
// handler for an s3 event
exports.handler = vandium.s3( (records) => {
let bucket = record[0].s3.bucket.name;
let key = record[0].s3.object.key;
console.log( `event triggered on bucket: ${bucket}, key: ${key}` );
});
For handling API Gateway proxy events, Vandium simplifies JWT processing, input validation and method handling while reducing overall code
that you need to write, maintain and test. Typical handler for a GET
method request for API Gateway would look like:
const vandium = require( 'vandium' );
const User = require( './user' );
const cache = require( './cache' );
exports.handler = vandium.api()
.GET( (event) => {
// handle get request
return User.get( event.pathParameters.name );
})
.finally( () => {
// close the cache if open - gets executed on every call
return cache.close();
});
In the above example, the handler will validate that the event is for API Gateway and that it is a GET
HTTP request. Note that the User
module used Promises to handle the asynchronous calls, this simplifies the code, enhances readability and reduces complexity.
Vandium allows you to create a compound function for handling different types of HTTP requests.
const vandium = require( 'vandium' );
const User = require( './user' );
const cache = require( './cache' );
exports.handler = vandium.api()
.GET( (event) => {
// handle get request
return User.get( event.pathParameters.name );
})
.POST( {
// validate
body: {
name: vandium.types.string().min(4).max(200).required()
}
},
(event) => {
// handle POST request
return User.create( event.body.name );
})
.PATCH( {
// validate
body: {
age: vandium.types.number().min(0).max(130)
}
},
(event) => {
// handle PATCH request
return User.update( event.pathParameters.name, event.body );
})
.DELETE( (event) => {
// handle DELETE request
return User.delete( event.pathParameters.name );
})
.finally( () => {
// close the cache if open - gets executed on every call
return cache.close();
});
The individual HTTP methods have their own independent paths inside the proxied handler, each with their own ability to validate specific event parameters as required.
Vandium 4's event handler mechanism allows targeted handling of event specific scenarios and thus code written using Vandium 3.x will
not be compatible with this version. To migrate your Vandium 3 code, use a targeted event handler or the
generic
event.
For documentation on how to use vandium in your project, please see our documentation page.
We'd love to get feedback on how to make this tool better. Feel free to contact us at [email protected]