title: AWS Lambda times out connecting to RedShift
body: <p>My Redshift cluster is in a private VPC. I've written the following AWS Lamba in Node.js which should connect to Redshift (dressed down for this question):</p>
  
  <pre><code>'use strict';
  console.log('Loading function');
  
  const pg = require('pg');
  
  exports.handler = (event, context, callback) =&gt; {
  var client = new pg.Client({
      user: 'myuser',
      database: 'mydatabase',
      password: 'mypassword',
      port: 5439,
      host: 'myhost.eu-west-1.redshift.amazonaws.com'
  });
  
  
      // connect to our database
      console.log('Connecting...');
      client.connect(function (err) {
          if (err) throw err;
  
          console.log('CONNECTED!!!');
  
      });
  
  };
  </code></pre>
  
  <p>I keep getting <strong>Task timed out after 60.00 seconds</strong> unfortunately. I see in the logs "<em>Connecting...</em>", but never "<em>CONNECTED!!!</em>".</p>
  
  <p>Steps I've taken so far to get this to work: </p>
  
  <ul>
  <li>As per <a href="https://stackoverflow.com/questions/40351422/connect-lambda-to-redshift-in-different-availability-zones/42684795#42684795">Connect Lambda to Redshift in Different Availability Zones</a> I have the Redshift cluster and the Lamba function in the <strong>same VPC</strong></li>
  <li>Also Redshift cluster and the Lamba function are on the <strong>same subnet</strong></li>
  <li>The Redshift cluster and the Lamba function share the <strong>same security group</strong></li>
  <li>Added an <strong>inbound rule</strong> at the security group of the Redshift cluster as per the suggestion here (<a href="https://github.com/awslabs/aws-lambda-redshift-loader/issues/86" rel="noreferrer">https://github.com/awslabs/aws-lambda-redshift-loader/issues/86</a>)</li>
  <li>The <strong>IAM role</strong> associated with the Lamba Function has the following policies: <em>AmazonDMSRedshiftS3Role, AmazonRedshiftFullAccess, AWSLambdaBasicExecutionRole, AWSLambdaVPCAccessExecutionRole, AWSLambdaENIManagementAccess</em> scrambled together from this source: <a href="http://docs.aws.amazon.com/lambda/latest/dg/vpc.html" rel="noreferrer">http://docs.aws.amazon.com/lambda/latest/dg/vpc.html</a> (I realize I have some overlap here, but figured that it shouldn't matter)</li>
  <li>Added <strong>Elastic IP</strong> to the Inbound rules of the Security Group as per an answer from a question listed prior (even if I don't even have a NAT gateway configured in the subnet)</li>
  <li>I <strong>don't</strong> have <em>Enhanced VPC Routing</em> enabled because I figured that I don't need it.</li>
  <li>Even tried it by adding the Inbound rule <strong>0.0.0.0/0 ALL types, ALL protocols, ALL ports</strong> in the Security Group (following this question: <a href="https://stackoverflow.com/questions/36893627/accessing-redshift-from-lambda-avoiding-the-0-0-0-0-0-security-group">Accessing Redshift from Lambda - Avoiding the 0.0.0.0/0 Security Group</a>). <strong>But same issue!</strong></li>
  </ul>
  
  <p>So, does anyone have any suggestions as to what I should check? </p>
  
  <p>*I should add that I am not a network expert, so perhaps I've made a mistake somewhere.</p>