Use connection pools that persist across function invocations
Use to manage the lifecycle of database connections established by serverless functions. Connection pools check connection health and re-establish broken connections in the event of a communication error. When creating connection pools in serverless functions:- Set the maximum connection pool size to 1, unless your function is multi-threaded and establishes multiple concurrent requests to your database within a single function instance.
- Do not set a minimum idle connection count. The connection pool should be free to open connections as needed.
- If supported by your pooling library, set the maximum lifetime on the connection pool to 30 minutes.
- node.JS
- Python
The following node.js code implements this pattern:

