gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 19:47:18 25 4
gpt4 key购买 nike

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

    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

我得到以下堆栈跟踪:
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

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

以下是一些 GitHub 问题,可能会提供额外的上下文:
  • https://github.com/aws/aws-lambda-dotnet/issues/288
  • https://github.com/npgsql/npgsql/issues/1984

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

    如果我可以提供任何其他信息,请告诉我。谢谢!

    最佳答案

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

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

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

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

    我希望您会喜欢运行 PostgreSQL 的 AWS RDS,我觉得它很棒。

    关于.net - AWS Lambda 上带有 netcoreapp2.0 的 Npgsql 无法连接(有超时) - 我该如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50744391/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com