I couldn't find a completely straight forward lambda function, using NodeJS and AWS SDK v3 to test RDS.
So here's the one I cobbled together. It logs in and runs 'show tables'.
It requires a lambda layer with the mysql nodejs library.
import mysql from 'mysql';
var connection = mysql.createConnection({
host: "blah.amazonaws.com",
user: "userName",
password: "password",
database: "dbName",
timezone: 'utc'
});
connection.connect();
export function handler(event, context, callback) {
connection.query('show tables', function (error, results, fields) {
if (error) {
connection.destroy();
throw error;
} else {
// connected!
console.log(results);
callback(error, results);
connection.end(function (err) { callback(err, results); });
}
});
};
Top comments (0)