AWS Lambda - 无法连接到 VPC 中的 SQL Server RDS [英] AWS Lambda - Unable to connect to SQL Server RDS in VPC

查看:46
本文介绍了AWS Lambda - 无法连接到 VPC 中的 SQL Server RDS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 VPC 中的 AWS Lambda 连接到我的 SQL Server RDS 实例(使用 .net core).

I am trying to connect to my SQL Server RDS instance from AWS Lambda in my VPC (using .net core).

当我尝试运行 Lambda 函数时,它返回:

When I attempt to run the Lambda function, it returns:

"errorType": "SqlException", "errorMessage": "Connection Timeout Expired.在登录后阶段超时时间已过.连接可能在等待服务器完成登录过程并响应时超时;或者它可能在尝试创建多个活动连接时超时.尝试连接到此服务器所花费的持续时间是 - [登录前]初始化=781;握手=1957;[登录]初始化=40;身份验证=122;[登录后] complete=12219;",

"errorType": "SqlException", "errorMessage": "Connection Timeout Expired. The timeout period elapsed during the post-login phase. The connection could have timed out while waiting for server to complete the login process and respond; Or it could have timed out while attempting to create multiple active connections. The duration spent while attempting to connect to this server was - [Pre-Login] initialization=781; handshake=1957; [Login] initialization=40; authentication=122; [Post-Login] complete=12219;",

我已经配置了以下内容:

I have configured the following:

  • RDS 实例和 Lambda 都在同一个 VPC 中
  • RDS 实例和 Lambda 都在同一个可用区和子网中
  • Lambda 位于自己的安全组中
  • RDS 实例安全组已为 Lambda SG 授予端口 1433 的权限
  • Lambda IAM 角色拥有 AWSLambdaFullAccess 和 AWSLambdaVPCAccessExecutionRole 的权限
  • MSSQL 连接字符串(端点、用户 ID、密码等)在同一 VPC/AZ/子网中的 EC2 实例中工作.

连接字符串看起来像这样(使用 Dapper 作为我的 ORM)

The connection string looks like this (using Dapper as my ORM)

string dbconnstr = @"server=vpc100-db.xyz.us-west-1.rds.amazonaws.com;database=dbMyDb;user id=sa;password=mypwd;";

知道我错过了什么吗?

推荐答案

已解决.数据库引擎版本是问题.

Solved. DB engine version was the issue.

事实证明,这不是 Lambda 或 VPC 和 RDS 的权限问题.无法从 Lambda(通过 c# .net core)连接到 RDS 是数据库版本!我正在连接到一个 RDS MS SQL 2008 R2,它使用本地代码而不是 Lambda.当我将 RDS 目标数据库更改为 MS SQL 2016 时,它起作用了!

It turns out it wasn't a permission problem with Lambda or the VPC and RDS. The inability to connect from Lambda (via c# .net core) to the RDS was the database version! I was connecting to a RDS MS SQL 2008 R2 which worked from local code but not from Lambda. When I changed the RDS target db to MS SQL 2016 it worked!

这篇关于AWS Lambda - 无法连接到 VPC 中的 SQL Server RDS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆