- 最新
- 最多得票
- 最多評論
I can't speak to what your exact issue is. Every time your Lambda function runs, you may be establishing a new database connection. Since Lambda reuses execution environments, it is recommended that the DB connection be established outside of the init code and left open. Additionally It could be a security issue, depending on your configuration. Is your DB Instance located in a private subnet? Do you have Security Group rules that only allow DB traffic from the Lambda functions?
Database connection management in a serverless environment is a common challenge, there is a tool to help you manage it.
RDS Proxy for PostgreSQL.
This can be setup for most apps without code changes. The idea is to fix connection management by connection pooling and multiplexing. You can also use RDS Proxy can also help add another layer of security and enforce IAM authentication for databases as well as securely store credentials in AWS Secrets Manager rather than in code.
RDS proxy info https://aws.amazon.com/rds/proxy/
A Lab using RDS Proxy for PostgreSQL https://catalog.us-east-1.prod.workshops.aws/workshops/2a5fc82d-2b5f-4105-83c2-91a1b4d7abfe/en-US/3-intermediate/rds-proxy
Security Group settings for Lambda connections: https://aws.amazon.com/premiumsupport/knowledge-center/connect-lambda-to-an-rds-instance/
Also see this post on RDS and Lambda - https://repost.aws/questions/QUdJCGX5f1SD-OESCqqOCT_w/rds-connections-in-lambda
Thank you for all the details we have definlty not done the right things the right way we are going to change that. By the way we find our bug we did not added a "client.end()" at the end of our lambda that's why db connection keep added up. In the mean time the main issue is fixed. But we are going to change our architecture to be more secure and efficient thanks to your help. Best,
相關內容
- 已提問 6 個月前