Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

lambda-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

lambda-wrapper - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

44

index.js
// Wrapper class for AWS Lambda
function Wrapped(mod, options) {
if (options == null) {
options = {};
}
function Wrapped(mod) {
this.lambdaModule = mod;
var handler = options.handler || 'handler';
if (mod[handler]) {
this.handler =mod[handler];
}
}
Wrapped.prototype.run = function(event, callback) {
var lambdacontext = {
Wrapped.prototype.runHandler = function(event, customContext, callback) {
var callback;
var defaultContext = {
succeed: function(success) {

@@ -22,5 +32,17 @@ return callback(null, success);

var lambdaContext = customContext;
if (!lambdaContext.succeed) {
lambdaContext.succeed = defaultContext.succeed;
}
if (!lambdaContext.fail) {
lambdaContext.fail = defaultContext.fail;
}
if (!lambdaContext.done) {
lambdaContext.done = defaultContext.done;
}
try {
if (this.lambdaModule.handler) {
this.lambdaModule.handler(event, lambdacontext, callback);
if (this.handler) {
this.handler(event, lambdaContext, callback);
} else {

@@ -51,2 +73,6 @@ var AWS = require('aws-sdk');

}
}
Wrapped.prototype.run = function(event, callback) {
return this.runHandler(event,{},callback);
};

@@ -56,4 +82,4 @@

function wrap(mod) {
var wrapped = new Wrapped(mod);
function wrap(mod, options) {
var wrapped = new Wrapped(mod, options);

@@ -75,4 +101,4 @@ return wrapped;

// static init/run interface for backwards compatibility
init: function(mod) {
latest = wrap(mod);
init: function(mod, options) {
latest = wrap(mod, options);
},

@@ -79,0 +105,0 @@ run: function(event, callback) {

{
"name": "lambda-wrapper",
"version": "0.1.0",
"version": "0.1.1",
"description": "Wrapper for running Amazon Lambda modules locally",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -29,5 +29,11 @@ # lambda-wrapper

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)
Documentation for valid propreties in the Lambda context object are documented here http://docs.aws.amazon.com/lambda/latest/dg/nodejs-prog-model-context.html
## Development
Run module tests using
Please run module tests in a Node 4 environment prior to submitting PRs using

@@ -37,6 +43,7 @@ npm run test

Live lambda run test requires that the function in lambdaWrapper-test.js is deployed
to your AWS account as 'lambdaWrapper-test'.
to your AWS account as 'lambdaWrapper-test'.
## Release History
* 2016/07/26 - v0.1.1 - Support for alternative handler. runHandler method for passing custom context.
* 2016/04/26 - v0.1.0 - Support for running lambda functions also from AWS

@@ -43,0 +50,0 @@ * 2016/04/26 - v0.0.6 - Support for NodeJS 4.3 runtime (and callback notation)

@@ -24,2 +24,16 @@ var testMod1 = {

var testMod4 = {
myHandler: function(event,context,callback) {
callback(null, event);
}
}
var testMod5 = {
handler: function(event,context,callback) {
callback(null, {
test: context.functionName
});
}
}
var wrapper = require('../index.js');

@@ -68,2 +82,20 @@ var expect = require('chai').expect;

it('wrap + run module 4 (alternate handler)', function(done) {
var w4 = wrapper.wrap(testMod4, {
handler: 'myHandler'
});
w4.run({test: 'cbsuccess'}, function(err, response) {
expect(response.test).to.be.equal('cbsuccess');
done();
});
});
it('wrap + runHandler module 5 (custom context)', function(done) {
var w5 = wrapper.wrap(testMod5);
w5.runHandler({test: 'cbsuccess'}, {functionName: 'testing'}, function(err, response) {
expect(response.test).to.be.equal('testing');
done();
});
});
it('can call lambda functions deployed in AWS', function(done) {

@@ -70,0 +102,0 @@ var wLive = wrapper.wrap({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc