title: AWS Lambda RDS connection timeout
body: <p>I'm trying to write a Lambda function using Node.js which connects to my RDS database. The database is working and accessible from my Elastic Beanstalk environment. When I run the function, it returns a timeout error.</p>
  
  <p>Tried to increase the timeout up to 5 minutes with the exact same result.</p>
  
  <p>The conclusion I came to after some research is that it's probably a security issue but couldn't find the solution in Amazon's documentation or in <a href="https://stackoverflow.com/questions/35880022/error-connect-etimedout-rds-lambda">this</a> answer (which is the only one I could find on the topic).</p>
  
  <p>Here are the security details:</p>
  
  <ul>
  <li>Both the RDS and the Lambda are in the same security group.</li>
  <li>The RDS has All traffic inbound and outbound rules.</li>
  <li>The Lambda has AmazonVPCFullAccess policy in it's role.</li>
  </ul>
  
  <p>My code is:</p>
  
  <pre><code>'use strict';
  console.log("Loading getContacts function");
  
  var AWS = require('aws-sdk');
  var mysql = require('mysql');
  
  exports.handler = (event, context, callback) =&gt; {
  
     var connection = mysql.createConnection({
          host     : '...',
          user     : '...',
          password : '...',
          port     : 3306,
          database: 'ebdb',
          debug    :  false
      });
  
      connection.connect(function(err) {
        if (err) callback(null, 'error ' +err);
        else callback(null, 'Success');
      });
  
  };
  </code></pre>
  
  <p>The result I'm getting is:</p>
  
  <pre><code>"errorMessage": "2017-03-05T05:57:46.851Z 9ae64c49-0168-11e7-b49a-a1e77ae6f56c Task timed out after 10.00 seconds"
  </code></pre>