Lambda to RDS database connection takes 6 seconds.

0

I have a Lambda function and a Postgres Serverless V2 RDS instance in us-west-2. The Lambda function frequently takes 6 seconds to establish a database connection to the RDS instance with IAM Authentication, and I have profiled the code to confirm that the time is spent on the actual connection process, not on cold starts, or creating the IAM Authentication token. Below you can see a sample from X-Ray:

Enter image description here

You can see that the connection function is taking 6 seconds. There is also a subsegment which is getting the IAM Auth token in 150ms. The rest of the time is spent connecting. This is a relatively new trend (last couple of days), because it just started tripping my Cloudwatch Alarms.

My backend code is Python 3.11, using psycopg2. After the IAM Auth token is negotiated, I immediately call psycopg2.connect and the function completes. So there is nothing else taking time, and I am fairly confident that there is something wrong with the network or the database.

How can I debug this? How can I improve this connection time?

1개 답변
1
수락된 답변

I had 2 pending database maintenance actions. One for a postgres minor version upgrade, and another for an OS patch. I applied both of those upgrades and the connectivity latency has dropped back down to sub-second. This suggests that the db or the OS had accumulated some connection cruft that was slowing down its ability to provision new connections. I hope this helps someone else.

답변함 한 달 전
profile picture
전문가
검토됨 한 달 전
profile pictureAWS
전문가
검토됨 한 달 전
AWS
지원 엔지니어
검토됨 한 달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠