Skip to content

Instantly share code, notes, and snippets.

@ashutoshpw
Created December 22, 2020 19:10
Show Gist options
  • Save ashutoshpw/68cdc2a5e22599db5693ed13a1d95d92 to your computer and use it in GitHub Desktop.
Save ashutoshpw/68cdc2a5e22599db5693ed13a1d95d92 to your computer and use it in GitHub Desktop.
ConnectToMySQLFromAWSLambda
'use strict';
const mysql = require('mysql'); // require mysql
// If 'client' variable doesn't exist
if (typeof client === 'undefined') {
// Connect to the MySQL database
var client = mysql.createConnection({
// your connection info
});
client.connect()
}
module.exports.handler = (event, context, callback) => {
// This will allow us to freeze open connections to a database
context.callbackWaitsForEmptyEventLoop = false;
client.query('SELECT * FROM `table_name`', function (error, results) {
callback(null, results)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment