serverlessify
v0.6.2
Published
Utility to simulate AWS Lambda event sources and write a server for Serverless functions
Downloads
67
Maintainers
Readme
Serverlessify
A tool to put back the server in Serverless functions!
Do you wanted to deploy your NodeJS AWS Lambda with Serverless but then you have been told:
Well, you should just start with a monolith and broke it up in microservices later...
We have got you covered! Use Serverlessify to write a server which serves Serverless lambdas as if they were on AWS. Later, actually deploying your lamndas with Serverless will just be one command away.
Usage
See Serverlessify Starter Kit for a full working usage example.
Install serverlessify with:
npm install --save serverlessify
Configure serverlessify and use it:
const serverlessify = require('serverlessify');
const sls = serverlessify({ http, authorizers });
sls(
{ ... }, // Serverless configuration object
{ ... } // Handlers
);
Options
For the moment, only http
events are supported
http
: (required) an map with http event handler configuration:eventHandler
: (required) An Express app instance that will be configured to work like AWS API Gateway for the Serverless funcitons that has an http event source.getPrincipalIdFromReq
: a function that should return a string sent to the lambda handler asprincipalId
. The function will recive the httpreq
parameter.wrapLambda
: a function that will be called with a lambda function as parameter. A new function should be returned with should in turn call the given lamnda. This is useful if common logic like error handling or promise lambdas should be added to all http handle lambdas.authorizers
: a map of global authorizers that will be available to Serverless http event authorizer configuration asarn
sauthorizersCacheSet
afunction({key, value, ttl}, cb)
used to set an entry in a custom cache to save calls to the authorizer. ttl defaults to 300 (ms) and should be used to invalidate the cache if aauthorizersCacheGet
is received after that time. The callbackcb
should be called after the cache has been set.authorizersCacheGet
afunction(key, cb)
used to retireve a cached item. This function should call the callback with a falsy value if there is no cache for the given key or if the cache item is expired. The callback is afunction(error, value)
.