Skip to content

Instantly share code, notes, and snippets.

@jwulf
Created October 6, 2015 16:04
Show Gist options
  • Save jwulf/4db4fd47d23915573894 to your computer and use it in GitHub Desktop.
Save jwulf/4db4fd47d23915573894 to your computer and use it in GitHub Desktop.
/**
* AWS Module: Action: Modularized Code with Promise for Asynchronous functions
*/
var Promise = require('bluebird');
// Export For Lambda Handler
module.exports.run = function(event, context, cb) {
return action(event).then(function(result) {
cb(null, result);
}).error(function(error) {
cb(error, null);
});
};
// Your Code
var action = function(event) {
return new Promise(function(resolve, reject) {
// Do your thing here
var asynchronousFunction = event;
// Inside your asychronous callback put this:
if (asynchronousFunction.succeed) {
resolve('Yay!');
} else {
reject({error: 'Boo!'});
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment