Skip to content
This repository was archived by the owner on Aug 8, 2024. It is now read-only.

spring-media/aws-lambda-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status npm version dependencies

aws-lambda-router

A small library providing routing for AWS ApiGateway Proxy Integrations and SNS...

Install

$ npm install aws-lambda-router

Usage

const router = require('aws-lambda-router');

exports.handler = router.handler(
    // the router-config contains configs for every type of 'processor'
{
    // for handling an http-call from an AWS Apigateway proxyIntegration we provide the following config:
    proxyIntegration: {
        // activate CORS on all http-methods:
        cors: true,
        routes: [
            {
                // the request-path-pattern to match:
                path: '/graphql',
                // http method to match
                method: 'POST',
                // provide a function to be called with the propriate data
                action: request=>doAnything(request.body)
            },
            {
                // request-path-pattern with a path variable:
                path: '/article/:id',
                method: 'GET',
                // we can use the path param 'id' in the action call:
                action: request=>getSomething(request.paths.id)
            },
            {
                path: '/:id',
                method: 'DELETE',
                action: request=>deleteSomething(request.paths.id)
            }
        ],
        debug: true,
        errorMapping: {
            'NotFound': 404,
            'RequestError': 500
        }
    },
    // for handling calls initiated from AWS-SNS:
    sns: {
        routes: [
            {
                // a regex to match the content of the SNS-Subject:
                subject: /.*/,
                // Attention: the message is JSON-stringified 
                action: sns => service.doSomething(JSON.parse(sns.Message))
            }
        ]
    }
});

local developement

The best is to work with npm link

See here: http://vansande.org/2015/03/20/npm-link/

Release History

  • 0.2.0 Attention: breaking changes for configuration; add SNS event process
  • 0.1.0 make it work now
  • 0.0.1 initial release