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.json
to include thevandium-serverless
plugin.
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 = ; /*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 )});*/ moduleexportshandler = ;
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.json
file for each Lambda function, and runnpm install vandium --save
in each function directory. This option results in smaller Lambda functions, but multiplenode_modules
andpackage.json
paths to maintain. -
Use the
package.json
in the root directory of your Serverless project, and runnpm install vandium --save
there. To use this option you will have to modify thehandler
property in thes-function.json
files to include the full path to the function handler starting from the subdirectory in the project root directory. It will look something likefunctionName/handler.handler
orlib/functionName/handler.handler
depending 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_modules
andpackage.json
). -
You can store your dependencies anywhere you decide to place an additional
node_modules
andpackage.json
. Just remember yourhandler
property 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.json
would 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