title: AWS Lambda .NET Core Function - public HTTP request results in Resource temporarily unavailable error on VPC
body: <p>I am trying to set up a basic .NET Core 2.1 Lambda function that can access private VPC web APIs as well as public Internet web APIs. However, as soon as the function is associated with a VPC, it can no longer access the public Internet.</p>
  
  <p>I tried the following (based on <a href="https://www.youtube.com/watch?v=Il34sBQbfXE" rel="nofollow noreferrer">this YouTube tutorial</a>):</p>
  
  <ul>
  <li>Created a new private subnet with CIDR block 172.18.10.0/24 .</li>
  <li>Created a new NAT gateway and associated with a public subnet that is already included in a route table with an Internet gateway at 0.0.0.0/0 and created a new EIP for the NAT gateway.</li>
  <li>Created a new route table, added Destination 0.0.0.0/0 to the NAT gateway and associated the route table with the newly created private subnet.</li>
  </ul>
  
  <p>In the Lambda function:</p>
  
  <ul>
  <li>Added function to the VPC.</li>
  <li>Added function to the newly created private subnet.</li>
  <li>Added security group with the following: Inbound Port 0 - 65535, Outbound Ports All Destination 0.0.0.0/0 .</li>
  </ul>
  
  <p>Here is the Lambda function I am testing:</p>
  
  <pre><code>using System.Net.Http;
  using System.Net;
  using System;
  
  using Amazon.Lambda.Core;
  using Amazon.Lambda.SQSEvents;
  
  // Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
  [assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
  
  namespace MyFunction
  {
      public class Function
      {
          public void FunctionHandler(SQSEvent sqsEvent, ILambdaContext context)
          {
              using (HttpClient client = new HttpClient())
              {
                  Console.WriteLine($"Sending HTTP request.");
                  HttpResponseMessage response = client.GetAsync($"http://dummy.restapiexample.com/api/v1/employee/18677").Result;
                  Console.WriteLine($"Response received.");
                  var content = response.Content.ReadAsStringAsync().Result;
                  Console.WriteLine($"Response content: {content}");
              }
          }
      }
  }
  </code></pre>
  
  <p>When triggering this function, the output is the following:</p>
  
  <pre><code>Sending HTTP request.
  One or more errors occurred. (Resource temporarily unavailable): AggregateException 
    at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification) 
    at MyFunction.Function.FunctionHandler(SQSEvent sqsEvent, ILambdaContext context) 
    in C:\__temp__\basic_lambda_func\Function.cs:line 20 at System.
  </code></pre>
  
  <p>When the Lambda function is not on the VPC it works fine. Any ideas what might be causing the issues on the VPC?</p>