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

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

问题描述

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

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,pwd等)从同一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核心)连接到RDS是数据库版本!我正在连接到RDS MS SQL 2008 R2,该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天全站免登陆