Function queries data from an Aurora database. Aurora database is the MySQL engine therefore, I'm querying it with a MySQL NPM module. If there is something better, I'm all ears.

The calling function has a try-catch block to manage exceptions. This function just connects to Aurora, submits a query, and displays the results to the console.

const mysql = require('mysql');

function aurora_query_decorator(host, user, password, port, database) {
    const esb_db_connectionstring = {
        "host" : host,
        "user" : user,
        "password" : password,
        "port" : port,
        "database" : database,
        "connectTimeout" : 5000
    console.log('Connection String: ', esb_db_connectionstring);

    console.log("Attempting to connect to Aurora...");
    const esb_db = mysql.createConnection(esb_db_connectionstring);

    esb_db.connect( (error) => {
        if (error) throw error;

        const esb_db_query_sql = "select * from things";
        console.log('Query: ', esb_db_query_sql);

        console.log("Attempting to query Aurora...");
        esb_db_query = esb_db.query(esb_db_query_sql);

        esb_db_query.on('error', error => { throw error } );

        esb_db_query.on('fields', data => { console.log(data) } );

        esb_db_query.on('end', () => { esb_db.end() } );


Looking for general feedback. All constructive feedback welcome.

Ultimately, I'll be querying Aurora from Lambda functions. Does it make sense to try to pool connections?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.