Pete Lunenfeld
Pete Lunenfeld

Reputation: 1707

AWS Lambda - Unable to connect to SQL Server RDS in VPC

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

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

"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:

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;";

Any idea what I'm missing?

Upvotes: 0

Views: 2833

Answers (1)

Pete Lunenfeld
Pete Lunenfeld

Reputation: 1707

Solved. DB engine version was the issue.

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!

Upvotes: 1

Related Questions