Giter Site home page Giter Site logo

dy604 / vandium-node Goto Github PK

View Code? Open in Web Editor NEW

This project forked from vandium-io/vandium-node

0.0 2.0 0.0 716 KB

AWS Lambda framework for building functions using Node.js for API Gateway, IoT applications, and other AWS events.

License: BSD 3-Clause "New" or "Revised" License

JavaScript 100.00%

vandium-node's Introduction

Build Status npm version

Vandium

AWS Lambda framework for building functions using Node.js for API Gateway, IoT applications, and other AWS events.

Features

  • 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

Installation

Install via npm.

npm install vandium --save

Getting Started

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.

Compatibility Issues with Vandium 3 Projects

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.

Documentation

For documentation on how to use vandium in your project, please see our documentation page.

Feedback

We'd love to get feedback on how to make this tool better. Feel free to contact us at [email protected]

License

BSD-3-Clause

vandium-node's People

Contributors

aglazer avatar dc00p avatar richardhyatt avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.