5

I deployed a RDS Aurora cluster for postgresql 11 in AWS. My lambda is talking to this cluster via IAM authentication. Since lambda is serverless, I have to create a connection to database every time my lambda is triggered and close the connection when it finishes. It is not great since creating db connection is heavy and takes time. I have used xray to observe the connection performance which takes 150ms to create a new connection. It also gives a lot load on db cluster since there will be many short lived connections on db.

After some searching I found RDS proxy is designed to solve the problem. So I deployed RDS proxy to use username/password to connect to my Aurora cluster. And my lambda connects to RDS proxy via IAM authentication.

When I observe the creating connection performance, it becomes worse. It takes more than 500ms to create a connection and sometimes it even takes more than 1 second.

How come it is worse when using RDS proxy? Is there anything I didn't configure in the proxy?

jtoberon
  • 8,706
  • 1
  • 35
  • 48
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
  • What language is your lambda written in? You can probably use a connection pool even in a lambda - while the handler is called multiple times, the environment stays the same. – Bergi Feb 24 '21 at 01:07
  • I am using `typescript` with `typeorm`. How does connection pool work inside lambda since it is stateless. – Joey Yi Zhao Feb 24 '21 at 02:14
  • How about the subsequent requests. I am just thinking that when you first request for a connection, the connection is created in RDS proxy and the same connection is reused for subsequent requests. I haven't used RDS proxy yet. – Arun Kamalanathan Feb 24 '21 at 06:23
  • I didn't measure the subsequene requests because create db connection is all I care about. Performing subscequence requests is basically done in the same connection channel and its performance is mainly caused by the query and index. – Joey Yi Zhao Feb 24 '21 at 06:41
  • IAM authentication – Joey Yi Zhao Jun 24 '21 at 06:38
  • Maybe try caching the token from IAM that's used as the password? I'm experiencing a similar problem in Java using RdsIamAuthTokenGenerator. – takteek Jun 24 '21 at 07:40
  • I am running application in lambda so caching is not available – Joey Yi Zhao Jun 24 '21 at 08:13
  • Hi @JoeyYiZhao did you find something about that issue? I am running into a similar one – OARP Jan 04 '23 at 05:51

0 Answers0