I am trying to a connect a AWS Lambda function to a database in RDS, I followed a few posts that have suggested they both need to be inside the same VPC, but have been told by Amazon support that this is not the case. Although I have tried a multi subnet VPC with nat gateway and security groups allowing access to each, with no prevail.
I am able to talk to the Database instances in SQL management studio or MySQL workbench without a problem.
10:13:00 2017-05-16T10:13:00.509Z Callback connection.connect() 10:13:00 2017-05-16T10:13:00.547Z Error ETIMEDOUT
I have tried a few different methods of connection now, I used an example as seen in the post, the only difference is this databases wasn't in RDS.
Querying a MySQL database from a NodeJS AWS Lambda Function
I have tried a MSSQL and MSSQL databases instances, both experiences a timeout on connection. I have attached all relevant policy's to the lambda function.
I have included below one of my simple tests, just to try and get a connection.
Test Code added below, not this at the bottom of a alexa call.
function mysqltest2() {
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'endpoint.rds.amazonaws.com',
user : 'user',
password : 'pass',
database : 'db'
});
var test;
console.log(`Intent Request`);
console.log('Then run MySQL code:');
connection.connect(function(err) {
console.log('Inside connection.connect() callback');
if (!err) {
console.log("Database is connected ... ");
connection.query("SELECT 1 + 1 AS solution",
function(err, result) {
console.log("Inside connection.query() callback")
if (!err) {
console.log(result);
console.log("Query Successful! Ending Connection.");
test = result;
connection.end();
} else {
console.log("Query error!");
}
});
} else {
console.log("Error connecting database ..." + err.message);
}
});
return test;
}