0

I am integrating lambda(Python) with RDS proxy, and for some of the examples on the web, I can see people initiating the connection outside the handler, and never closing it.

On the other hand, I have seen examples on which people initiate the connection within the handler.

So, what is the best practice? I assume if you go for the first approach, the idle client connection timeout(RDS proxy) should be short, otherwise you can surpass the connection limit.

Marcos Mussio
  • 61
  • 1
  • 7

1 Answers1

0

If we create the connection outside handler then the same connection can be used for warm starts which is good have if idle timeout is set appropriately.

If the connection is set inside handler then it'll have an overhead of creating and closing connections for each invocations.

Prashanna
  • 889
  • 1
  • 8
  • 13
  • Ok, but in this case I am using RDS proxy for managing the connections, so I want to re use them. The time out I set for idle connections in the proxy is 30 mins(default value in RDS proxy). – Marcos Mussio Mar 26 '21 at 21:52
  • 1
    Then it should be fine to have the connection outside handler. Even if new lambda instance starts a connection the proxy will map it to existing itself. – Prashanna Mar 27 '21 at 04:20