Skip to content

Commit

Permalink
Merge pull request #1 from laurisvan/master
Browse files Browse the repository at this point in the history
Inject the lambda module as an instance rather than path
  • Loading branch information
mpuittinen committed Sep 2, 2015
2 parents bed6f9a + 9d7f540 commit 21b17e4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
27 changes: 7 additions & 20 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,31 @@
// Pseudowrapper for AWS Lambda

var lambdaModule;

var _runner = function(event, callbackFn) {
var _runner = function(event, callback) {
if (!lambdaModule) {
return callbackFn('Module not initialized', null);
return callback('Module not initialized', null);
}

var lambdacontext = {
succeed: function(success) {
return callbackFn(null, success);
return callback(null, success);
},
fail: function(error) {
return callbackFn(error, null);
return callback(error, null);
}
};

try {
lambdaModule.handler(event, lambdacontext);
} catch (ex) {
callbackFn('Exception:' + ex.toString());
callback('Exception:' + ex.toString());
}
};

// Public interface for the module
module.exports = exports = {
init: function(modName) {
if (!modName) {
modName = '';
}

try {
lambdaModule = require(modName);
return this;
} catch (ex) {
lambdaModule = require(process.cwd() + '/' + modName);
return this;
}

return null;
init: function(mod) {
lambdaModule = mod;
},
run: _runner
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lambda-wrapper",
"version": "0.0.1",
"version": "0.0.2",
"description": "Wrapper for running Amazon Lambda modules locally",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 21b17e4

Please sign in to comment.