Latency issue between RDS and Lamda

0

We have APIs deployed on Lambda which read/write data on RDS. All these services are on same region (ap-southeast-2), but we are experiencing delay on RDS from Lambda. It takes around 5 seconds to update record on RDS. What could be the reason for the delay even though these services are configured on same region and is there a way to optimise the latency?

2개 답변
0

Five seconds seems like a long time. Have you tried the same operation from an EC2 instance? That might give you an idea as to where the problem might be.

You might also turn on debugging in whichever libraries you're using or perhaps instrument your code using X-Ray. Either way you're trying to track down where the delay is.

The delay could come from DNS resolution; it could come from establishing the TCP session to RDS; it could come from the database itself.

profile pictureAWS
전문가
답변함 2년 전
0

Which RDS flavor are you using? Have you configured the RDS Proxy - https://aws.amazon.com/rds/proxy/faqs/ and is lambda using the RDS Proxy? - https://aws.amazon.com/blogs/compute/using-amazon-rds-proxy-with-aws-lambda/

Also is your RDS inside a VPC and is your lambda VPC enabled?

To improve the performance of reads, have you implemented Read Replicas on your RDS database - https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/USER_ReadRepl.html

Also make sure that the database connection is being opened outside of the Event Handler block in your lambda code, as mentioned in the "Take advantage of execution environment reuse to improve the performance of your function" section of Lambda Best Practices, if you haven't done so already - https://docs.aws.amazon.com/lambda/latest/dg/best-practices.html

Apart from implementing the client on an EC2 machine, as Brett has suggested above, if your database is Postgres, MySQL or MariaDB, you may also want to try out installing the same version of the database in an EC2 machine and try accessing that database from your lambda function, just to eliminate that RDS is not the culprit.

profile pictureAWS
전문가
답변함 2년 전

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

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

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