A financial transaction processor uses an AWS Lambda function to validate account balances against an Amazon DynamoDB table. The Lambda function is configured to run inside a private subnet of a VPC to comply with security standards. During peak load, the system experiences a high rate of database connection timeouts and latency spikes. An analysis reveals that the Lambda function is establishing a new connection to DynamoDB during every invocation, and the outbound traffic to DynamoDB is routed via a NAT Gateway, leading to high data processing costs.
Which combination of actions will resolve the latency issues and reduce data transfer costs?
- ADeclare and initialize the DynamoDB client inside the Lambda handler function, and create an interface VPC endpoint for DynamoDB to bypass the NAT Gateway.
- BDeclare and initialize the DynamoDB client outside the Lambda handler function, hardcode static credentials with minimum permissions in the client initialization, and configure a public NAT Instance.
- CInstantiate the DynamoDB client inside the Lambda handler function, attach an Internet Gateway directly to the private subnet, and configure a security group to allow inbound traffic from DynamoDB.
- Declare and initialize the DynamoDB client outside the Lambda handler function, and create a gateway VPC endpoint for DynamoDB with a route table entry pointing to it from the private subnet.Cevap
Cevap
Declare and initialize the DynamoDB client outside the Lambda handler function, and create a gateway VPC endpoint for DynamoDB with a route table entry pointing to it from the private subnet.
The correct solution involves defining and instantiating the DynamoDB client outside the handler function. AWS Lambda reuses the execution context for subsequent invocations, allowing global variables and connections to persist. This reduces the latency of establishing new TCP connections. Additionally, routing traffic to DynamoDB via a gateway VPC endpoint eliminates NAT Gateway transit costs and reduces network latency by keeping traffic within the AWS network.
Adım Adım Çözüm
Anahtar Kavram
Optimization of AWS Lambda execution context reuse for database connections, and the implementation of gateway VPC endpoints for cost-effective, secure private routing to AWS services.
Tahmini Süre:2m 0s