> The code creates a MySQL connection during each invocation.
This is not a correct implementation for Lambda.
You shouldn't recreate a connection on every invocation. Instead, create your connection outside of your handler code. Then each invocation of a warm container will re-use the same handler. (1)
This will help cut down on cold start time, as well as help manage running out of connections.
You should limit your maximum number of concurrent invocations to be equal to the limit of your database threadpool. This is all in their documentation, as well as several blog posts. (2, 3, 4)
[1] https://docs.aws.amazon.com/lambda/latest/dg/services-rds-tu...
[2] https://www.jeremydaly.com/reuse-database-connections-aws-la...
[3] https://medium.com/faun/reusing-connections-lambda-functions...