A compliance scanning service utilizes an AWS Lambda function deployed in private subnets to access a private Amazon DocumentDB cluster. To validate document checksums, the function must also call an external verification service on the public internet. During high-concurrency event bursts, the Lambda function frequently exceeds its configured timeout when establishing connections to both DocumentDB and the external verification service. Which combination of steps should the developer take to resolve the timeouts and optimize connection performance?
- Configure a NAT Gateway in a public subnet, add a route to it in the private subnet's route table, and instantiate the DocumentDB client outside the Lambda handler function to enable connection reuse across warm starts.Cevap
- BRemove the Lambda function from the VPC so that it can access the public internet directly, and configure the DocumentDB security group to allow inbound traffic from the Lambda function's security group.
- CConfigure a NAT Gateway in the private subnet, and re-create the DocumentDB connection pool inside the handler function on every invocation to ensure that connections do not time out during execution context reuse.
- DAssociate an Internet Gateway directly with the private subnets, and configure the Lambda function to authenticate to the DocumentDB cluster using hardcoded master database credentials inside the handler code.
Cevap
Configure a NAT Gateway in a public subnet, add a route to it in the private subnet's route table, and instantiate the DocumentDB client outside the Lambda handler function to enable connection reuse across warm starts.
The correct option addresses both the connectivity and optimization issues. By placing a NAT Gateway in a public subnet and routing outbound traffic from the private subnet through it, the Lambda function can reach the public internet. By instantiating the DocumentDB client in the global scope (outside the handler), the function utilizes execution context reuse to cache the database connection pool, reducing connection setup overhead and latency for subsequent warm invocations.
Adım Adım Çözüm
Anahtar Kavram
VPC Lambda connectivity and execution context reuse optimization