vandium-serverless v1.1.0
vandium-serverless
Serverless plugin allowing you to create new Node.js 4.3 functions automatically wrapped with vandium.
Features
- Creates Serverless functions pre-wrapped with vanidum
- Adds HTTP response codes specific to vandium error conditions
- No need to remember wrap your Serverless functions in vandium manually
- Easy to use
- Integrates with Serverless Framework for AWS Lambda
- Supports Node.js 4.3.2
Installation
- Install via npm in the root folder of your Serverless project.
npm install vandium-serverless --save- Edit your
s-project.jsonto include thevandium-serverlessplugin.
{
"name": "yourprojectname",
"custom": {},
"plugins": [ "vandium-serverless" ]
}Getting Started
Run serverless function create to create a new function, as you would normally do with Serverless.
When prompted to select a runtime for the new function select 'nodejs4.3-vandium'.
Serverless: Please, select a runtime for this new Function
nodejs4.3
python2.7
> nodejs4.3-vandium
nodejs (v0.10, soon to be deprecated)Your newly created function is a standard Node.js 4.3 function wrapped with vandium.
'use strict';
const vandium = require( 'vandium' );
/*
vandium.validation( {
// your validation code here
// firstName: vandium.types.string().min( 4 ).max( 80 ).required(),
// lastName: vandium.types.string().min( 4 ).max( 80 ).required(),
// age: vandium.types.number().integer().min( 0 ).max( 120 )
});
*/
module.exports.handler = vandium( function( event, context, callback ) {
// your code goes here
callback( null, 'Your Vandium wrapped Serverless function ran succesfully!!!' );
});Vandium offers features such as input validation, SQL Injection detection, and JWT authentication. For a full list of features and instructions visit the vandium project page.
Packaging
In order to use the Vandium wrapper, Vandium must be installed as a third party dependency. The require( 'vandium' ) is already included at the top of the template Lambda function code. How you handle third party dependencies in your Serverless project is up to you, however here are several options based on the Serverless documentation.
Create a
package.jsonfile for each Lambda function, and runnpm install vandium --savein each function directory. This option results in smaller Lambda functions, but multiplenode_modulesandpackage.jsonpaths to maintain.Use the
package.jsonin the root directory of your Serverless project, and runnpm install vandium --savethere. To use this option you will have to modify thehandlerproperty in thes-function.jsonfiles to include the full path to the function handler starting from the subdirectory in the project root directory. It will look something likefunctionName/handler.handlerorlib/functionName/handler.handlerdepending on how you store your functions. This option will result in larger Lambda functions, since everything will be included in the Lambda function packaging, however there will only be one location for all dependencies (node_modulesandpackage.json).You can store your dependencies anywhere you decide to place an additional
node_modulesandpackage.json. Just remember yourhandlerproperty must include a path starting in the directory where the dependencies are stored. That entire directory will get packaged when your function is deployed. As an example,
parent
|
|-- functionName
| |
| |-- event.json
| |
| |-- handler.js
| |
| +-- s-function.json
|
|-- node_modules
|
+-- package.jsonwould require the handler property in s-function.json to look like "handler": "functionName/handler.handler"
Feedback
We'd love to get feedback on how you're using vandium-serverless and things we could add to make this tool better. Feel free to contact us at feedback@vandium.io