title: Npgsql with netcoreapp2.0 on AWS Lambda is unable to connect (has timeout) - how can I resolve?
body: <p>I'm trying to deploy a netcoreapp2.0 application to AWS Lambda that connects to Postgres on RDS.  The following code fails:</p>
  
  <pre><code>    let testConn = "Host=hostNameHere;Username=userNameHere;Password=passwordHere;Database=postgres";
      let conn = new NpgsqlConnection(testConn)
      try
          printfn "Trying to open a connection"
          conn.Open()
      with ex -&gt;
          printfn "Exception trying to open conn:\n%O" ex
  </code></pre>
  
  <p>I get the following stack trace:</p>
  
  <pre><code>System.TimeoutException: The operation has timed out.
  at Npgsql.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
  at Npgsql.NpgsqlConnector.&lt;RawOpen&gt;d__153.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at Npgsql.NpgsqlConnector.&lt;Open&gt;d__149.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at Npgsql.ConnectorPool.&lt;AllocateLong&gt;d__19.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at Npgsql.NpgsqlConnection.&lt;&gt;c__DisplayClass32_0.&lt;&lt;Open&gt;g__OpenLong|0&gt;d.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at Npgsql.NpgsqlConnection.Open()
  at Masse.Common.SQL.query[T](String connectString, SqlQuery q) in /home/nat/Projects/shopmasse-backend/fsharp/src/Masse.Common/Sql.fs:line 40
  </code></pre>
  
  <p>Does anyone know why this might fail with deployed to AWS lambda, but work locally on my machine?</p>
  
  <p>Here are some GitHub issues that may provide additional context:</p>
  
  <ul>
  <li><a href="https://github.com/aws/aws-lambda-dotnet/issues/288" rel="nofollow noreferrer">https://github.com/aws/aws-lambda-dotnet/issues/288</a></li>
  <li><a href="https://github.com/npgsql/npgsql/issues/1984" rel="nofollow noreferrer">https://github.com/npgsql/npgsql/issues/1984</a></li>
  </ul>
  
  <p>Some additional details:
  - DB Engine: PostgreSQL 9.6.6 
  - Npgsql version: 4.0
  - .NET version: netcoreapp2.0</p>
  
  <p>Please let me know if I can provide any additional information.  Thank you!</p>