DEV Community

Cover image for Test your mySQL / Aurora database with Lambda
Nick Triantafillou for AWS Heroes

Posted on

4

Test your mySQL / Aurora database with Lambda

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); });
        }
    });
};
Enter fullscreen mode Exit fullscreen mode

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay