1

I am trying to access a public AWS RDS mysql, it is publicly available , I can access the database from JetBrains DataGrip IDE below is config from the AWS RDS console:

RDS Config

When using the AWS lambda function below (also tried without the pool and with creating and ending connections on each execute), the output does not give me any errors. only output is the pool object...

Has anyone else had a similar problem? Is there a way to get more error information?

I know AWS has announced that they will be adding to the Lambda RDS integrations for VPS and such, but is there no option until then?

var mysql = require('mysql');
var pool = mysql.createPool({
connectionLimit: 10,
host: 'test.XXXXXXX.us-east-1.rds.amazonaws.com',
port: 3306,
user: 'user',
password: 'password',
database: 'theDB'
});

function execute(event, context) {

console.log(pool);
pool.getConnection(function (err, connection) {
    if (err) {
        console.error('error connecting: ' + err.stack);
        context.fail(err);
    } else {
        console.log('connected as id ' + connection.threadId);
        console.log("connect to db!!!!");

    }
    console.log(connection);
    connection.query('SELECT * FROM table', function (err, results, fields) {
        if (err) {
            context.fail(err);
        } else {
            console.log(results);
            console.log(fields);
            console.log("Select Done");
        }
    });
    connection.release();
});

context.done(null, null);

};

exports.handler = execute;

1 Answer 1

1

context.done() should be in pool.getConnection(function (err, connection) {...}).

pool.getConnection() is an asynchronous method.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, that was it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.