问题
I am looking for AWS Lambda to handle RDS Database connection pooling mechanism or do we have work around for this????
If we not having option for this i will face max connection error quickly..
回答1:
There are two aspects to the problem, I had similar issue and this is how I mitigated.
- Reusing the database connection pooling, Following is an example where declaring the connection object outside of the handler will help for boost the hot starts
https://github.com/jeffnoehren/Spotinst-Function-Examples/blob/master/node-mysql-connection/handler.js
Here is a good read - http://blog.spotinst.com/2017/11/19/best-practices-serverless-connection-pooling-database/
- second aspect of your problem, Reaching the maximum connections, no matter which connection pooling you are using if you don't throttle your lambda invocations there's a upper limit for the invocations. but you haven't mentioned how many requests you are handling. If your lambda invocations are asynchronous I would implement the request being enqueued in the SQS and consume those request asynchronously.
来源:https://stackoverflow.com/questions/48179587/aws-lambda-rds-database-connection-pooling