AWS Lambda上带有netcoreapp2.0的Npgsql无法连接(已超时) - 我该如何解决?

Nat*_*ins 3 .net f# npgsql amazon-web-services aws-lambda

我正在尝试将一个netcoreapp2.0应用程序部署到AWS Lambda,该应用程序连接到RDS上的Postgres.以下代码失败:

    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 ->
        printfn "Exception trying to open conn:\n%O" ex
Run Code Online (Sandbox Code Playgroud)

我得到以下堆栈跟踪:

System.TimeoutException: The operation has timed out.
at Npgsql.NpgsqlConnector.Connect(NpgsqlTimeout timeout)
at Npgsql.NpgsqlConnector.<RawOpen>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.<Open>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.<AllocateLong>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.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>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
Run Code Online (Sandbox Code Playgroud)

有没有人知道为什么这可能会因部署到AWS lambda而失败,但在我的机器上本地工作?

以下是一些可能提供其他上下文的GitHub问题:

一些额外的细节: - 数据库引擎:PostgreSQL 9.6.6 - Npgsql版本:4.0 - .NET版本:netcoreapp2.0

如果我能提供任何其他信息,请告诉我.谢谢!

Oli*_*ROT 7

连接超时通常表示防火墙问题.

您的连接请求被RDS实例的安全组阻止.

创建实例后,运行AWS控制台的计算机的IP将自动列入白名单.

访问PostgreSQL的任何其他外部或内部资源也必须列入白名单.

我希望你会喜欢运行PostgreSQL的AWS RDS,我发现它很棒.