-
-
Save jwulf/37bec881e03c6000bdfb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* 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