Home:ALL Converter>AWS Lambda - Access Public AWS RDS MySQL

AWS Lambda - Access Public AWS RDS MySQL

Ask Time:2016-01-17T14:46:14         Author:Brian

Json Formatter

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;

Author:Brian,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/34835888/aws-lambda-access-public-aws-rds-mysql
yy