Question

Difficulty: HardServerless Development with AWS Lambda

A developer is optimizing and troubleshooting an AWS Lambda function that reads transaction configurations from an Amazon DynamoDB table and then posts authorization requests to a third-party payment gateway via HTTPS.

The Lambda function is configured to run inside a VPC within two private subnets. The VPC has a Gateway VPC Endpoint configured for DynamoDB. During testing, the Lambda function successfully queries DynamoDB but fails with a network timeout error when attempting to connect to the payment gateway's external API. Additionally, Amazon CloudWatch logs show high execution latency during warm starts because the DynamoDB client is re-instantiated on every invocation.

Which two actions must the developer take to resolve the network timeout and optimize execution performance? (Select two.)

  1. Configure a route in the route tables of the private subnets to direct internet-bound traffic (0.0.0.0/00.0.0.0/0) to a NAT Gateway deployed in a public subnet.Answer
  2. Initialize the DynamoDB SDK client outside of the Lambda handler function to reuse the client instance across subsequent invocations.Answer
  3. C
    Enable the public IP mapping setting on the Elastic Network Interfaces (ENIs) assigned to the Lambda function in the private subnets.
  4. D
    Move the Lambda function to a public subnet within the VPC and configure its security group to allow inbound HTTPS traffic from the payment gateway.
  5. E
    Modify the Lambda function's IAM trust policy to allow the VPC Gateway Endpoint for DynamoDB to assume the execution role.

Answer

Configure a route in the route tables of the private subnets to direct internet-bound traffic to a NAT Gateway in a public subnet, and initialize the DynamoDB SDK client outside of the Lambda handler function.
To resolve the network timeout, the Lambda function needs internet access. Since it is located in private subnets, you must route its outbound traffic (0.0.0.0/00.0.0.0/0) to a NAT Gateway in a public subnet. Additionally, to optimize execution latency during warm starts, initializing the DynamoDB client outside the handler function allows Lambda to reuse the client instance from the execution context.

Step-by-Step Solution

1
Address the external API connection failure by checking the network route path.
The Lambda function is in private subnets and needs a path to the internet. Adding a route to a NAT Gateway in a public subnet allows outbound HTTPS requests.
Private subnets cannot reach the public internet directly and need a NAT Gateway for egress.
2
Address the high execution latency on warm starts by reviewing client initialization.
Move the DynamoDB client initialization code out of the handler block.
By placing initialization outside the handler, the client object is instantiated only once during cold start and reused across subsequent executions.

Key Concept

AWS Lambda VPC networking (NAT Gateway requirements) and execution context reuse optimization.
Estimated Time:2m 0s
Rate this question