You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Wrapper for running lambda modules locally, remotely via http or from AWS during development
Use
Initializing the local Lambda
// Loads the module in myModule/mymod.js
var lambdaFunc = require('myModule/mymod.js');
var lambda = require('lambda-wrapper').wrap(lambdaFunc);
Initializing a lambda wrapped by an http server
var lambda = require('lambda-wrapper').wrap('https://my-lambda-service/');
Initializing a lambda in AWS
var lambda = require('lambda-wrapper').wrap({
region: 'eu-west-1',
lambdaFunction: 'myFunctionName'
});
Running the function in the Lambda module
var event = { key1: 'val1', key2: val2 };
lambda.run(event, function(err, data) {
if (err) {
... handle error
}
... process data returned by the Lambda function
})
If you want to pass a custom context to the Lambda module (only when running local), use the runHandler method. e.g.
lambda.runHandler(event, customContext, callback)
Accessing a lambda running as a remote service can be useful when calling lambdas that sit in different projects.
E.g. Node Project A invokes Lambda in Project B.
Using e.g. serverless-offline-direct-lambda,
the lambda can be wrapped in an http server and called from project A.