title: AWS Lambda connecting to Internet
body: <h2>TL;TR</h2>
  
  <p>I am trying to connect to internet from AWS Lambda, I have a private subnet with a NAT Gateway but still the function cannot connect to internet...</p>
  
  <h2>Full Question</h2>
  
  <p>So I am trying to access internet with my AWS Lambda function. I have tried both Java and NodeJS 4 with no luck.</p>
  
  <p>I have a private VPC with a subnet: 10.0.10.0/24</p>
  
  <p><a href="https://i.stack.imgur.com/GZr78.png" rel="noreferrer"><img src="https://i.stack.imgur.com/GZr78.png" alt="enter image description here"></a></p>
  
  <p>As you can see I have added a rule to my NAT Gateway:</p>
  
  <p><a href="https://i.stack.imgur.com/5ACF5.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5ACF5.png" alt="enter image description here"></a></p>
  
  <p>I configured my AWS Lambda like this:</p>
  
  <p><a href="https://i.stack.imgur.com/w1Sy8.png" rel="noreferrer"><img src="https://i.stack.imgur.com/w1Sy8.png" alt="enter image description here"></a></p>
  
  <p>Selecting that subnet (10.0.10.0) and with a security group that is open to everything (both inbound and outbound)</p>
  
  <p>But yet when I try to download something from internet, the lambda times out:</p>
  
  <pre><code>'use strict';
  console.log('Loading function');
  
  var http = require("http");
  
  exports.handler = (event, context, callback) =&gt; {
      //console.log('Received event:', JSON.stringify(event, null, 2));
      console.log('value1 =', event.key1);
      console.log('value2 =', event.key2);
      console.log('value3 =', event.key3);
  
      var options = {
        host: 'www.virgilio.it',
        port: 80,
        path: '/'
      };
  
      http.get(options, function(res) {
        console.log("Got response: " + res.statusCode);
      }).on('error', function(e) {
        console.log("Got error: " + e.message);
      });
  
      callback(null, event.key1);  // Echo back the first key value
      // callback('Something went wrong');
  };
  </code></pre>
  
  <blockquote>
    <p>{
     "errorMessage": "2016-05-10T10:11:46.936Z 79968883-1697-11e6-9e17-1f46a366f324 Task timed out after 55.00
    seconds"
     }</p>
  </blockquote>
  
  <p>Is this a bug?</p>
  
  <p><strong>Note: the same function works If I don't select my VPC</strong></p>