Question

Difficulty: MediumDebugging Lambda Execution and Configuration Issues

A developer is troubleshooting an AWS Lambda function that is configured to access an Amazon RDS DB instance inside a private subnet of a custom VPC. The function also needs to call an external billing API over the public internet. During testing, the developer observes two issues: the function cannot establish a connection to the external billing API, and the database experiences connection exhaustion due to a high volume of database connections being created during peak traffic. Which two actions should the developer take to resolve these configuration and performance issues? (Select TWO.)

  1. Configure a NAT Gateway in a public subnet of the VPC and add a route pointing to it in the private subnet's route table.Answer
  2. Initialize the database connection client outside of the Lambda handler function to reuse connections across execution contexts.Answer
  3. C
    Deploy the Lambda function in a public subnet and enable the public IP assignment configuration on the function.
  4. D
    Create a Gateway VPC Endpoint for the external billing API and associate it with the private subnet's route table.
  5. E
    Add code inside the Lambda handler to explicitly close the connection and force execution context recycling after every invocation.

Answer

Configure a NAT Gateway in a public subnet of the VPC, add a route pointing to it in the private subnet's route table, and initialize the database connection client outside of the Lambda handler function.
To enable internet access for a Lambda function in a private VPC subnet, a NAT Gateway must be set up in a public subnet, and the private subnet's route table must route traffic bound for the internet to the NAT Gateway. Additionally, database connection clients should be declared globally outside the handler function to allow reuse of existing connections across subsequent warm executions of the same Lambda container instance.

Step-by-Step Solution

1
Analyze the network configuration of the Lambda function.
The Lambda function is inside a private subnet and cannot access the public internet directly.
To connect to the external billing API, the private subnet requires a route to a NAT Gateway located in a public subnet.
2
Analyze the database connection lifecycle within the Lambda function code.
Database connections are currently created inside the handler function on every invocation.
Declaring the database client globally (outside the handler) allows the connection to be reused across multiple warm execution context invocations, mitigating database connection exhaustion.

Key Concept

VPC Lambda internet access configurations and execution context reuse strategies.
Rate this question