A developer is deploying an AWS Lambda function that processes incoming telemetry data and writes it to an Amazon Aurora PostgreSQL database located in a private VPC subnet. During testing, the developer observes that the Lambda function is unable to establish a connection to Aurora, and the function's execution times out. Additionally, performance logs show significant latency during cold starts due to repeated database credential retrieval from AWS Secrets Manager.
Which two actions should the developer take to resolve the database connectivity issues and improve the cold start performance?
- Configure the Lambda function to run within the private subnets of the VPC, and associate the function with a security group that allows outbound traffic to the database.Cevap
- Instantiate the AWS SDK client for Secrets Manager and the database connection pool globally outside of the handler function.Cevap
- CDeploy the Lambda function inside the public subnets of the VPC and assign a public IP address directly to the Lambda function's execution configuration.
- DInstantiate the AWS SDK client for Secrets Manager and the database connection pool inside the handler function to ensure they are re-initialized on every invocation.
- EConfigure the IAM execution role of the Lambda function with a trust policy that permits the RDS database service principal to assume the role.
Cevap
To resolve the connectivity issues and improve performance, the developer should configure the Lambda function to run within the private VPC subnets with a security group that allows outbound traffic to the database, and instantiate the AWS SDK client and database connection pool globally outside the handler function.
The correct combination requires establishing network connectivity to a private database and optimizing cold start performance. Configuring the function to run in the private subnets with a security group that allows outbound access to the database resolves the database connectivity issue. Moving the instantiation of the SDK client and the database connection pool outside the handler function ensures these resources are reused across execution contexts, optimizing performance.
Adım Adım Çözüm
Anahtar Kavram
AWS Lambda VPC networking and execution context optimization