-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from laurisvan/master
Inject the lambda module as an instance rather than path
- Loading branch information
Showing
2 changed files
with
8 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters