title: AWS Lambda node.js ETIMEDOUT when accessing MySQL or MS SQL in RDS
body: <p>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. </p>
  
  <p>I am able to talk to the Database instances in SQL management studio or MySQL workbench without a problem.</p>
  
  <p>10:13:00
  2017-05-16T10:13:00.509Z Callback connection.connect()
  10:13:00
  2017-05-16T10:13:00.547Z Error ETIMEDOUT</p>
  
  <p>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.</p>
  
  <p><a href="https://stackoverflow.com/questions/42591610/querying-a-mysql-database-from-a-nodejs-aws-lambda-function">Querying a MySQL database from a NodeJS AWS Lambda Function</a></p>
  
  <p>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.</p>
  
  <p>I have included below one of my simple tests, just to try and get a connection.</p>
  
  <p>Test Code added below, not this at the bottom of a alexa call. </p>
  
  <pre><code>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;
    }
  </code></pre>