Question

Difficulty: MediumServerless Development with AWS Lambda

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?

  1. 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.Answer
  2. Instantiate the AWS SDK client for Secrets Manager and the database connection pool globally outside of the handler function.Answer
  3. C
    Deploy the Lambda function inside the public subnets of the VPC and assign a public IP address directly to the Lambda function's execution configuration.
  4. D
    Instantiate 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.
  5. E
    Configure the IAM execution role of the Lambda function with a trust policy that permits the RDS database service principal to assume the role.

Answer

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.

Step-by-Step Solution

1
Configure the Lambda function VPC settings.
The Lambda function is associated with the private subnets of the VPC and configured with a security group allowing outbound traffic to the database port.
This establishes the physical network connectivity from the Lambda function's elastic network interfaces (ENIs) to the private Aurora PostgreSQL database.
2
Refactor the Lambda function code to instantiate resources globally.
The database connection pool and Secrets Manager SDK client are defined outside the handler block.
This implements execution context reuse, ensuring these resources are created once during the cold start initialization phase and reused across subsequent warm invocations, thereby decreasing latency.

Key Concept

AWS Lambda VPC networking and execution context optimization
Rate this question