Skip to content

Instantly share code, notes, and snippets.

@jwulf
Created October 6, 2015 16:11
Show Gist options
  • Save jwulf/37bec881e03c6000bdfb to your computer and use it in GitHub Desktop.
Save jwulf/37bec881e03c6000bdfb 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) {
var getUsers() = function() {
var connection = mysql.createConnection({
host : '###',
user : '###',
password : '###',
database : '###'
});
connection.connect();
var results;
connection.query('myQuery', function (err, rows, fields) {
if (err) {
reject(err);
}
resolve(rows);
});
}});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment