Question

Difficulty: MediumServerless Development with AWS Lambda

A developer is writing an AWS Lambda function that processes telemetry data sent from a custom web portal. The function must make an HTTP POST request to an external third-party API and then write the processed telemetry record to an Amazon DynamoDB table. During load testing, the developer observes high latencies due to connection setup overhead on each invocation and database access errors when trying to write to DynamoDB.

Which two changes should the developer make to optimize the performance of the function and ensure secure access to DynamoDB? (Select two.)

  1. Instantiate the DynamoDB client and HTTP client outside the handler function to reuse connection pools across invocations.Answer
  2. Configure the Lambda function's IAM execution role with a policy allowing dynamodb:PutItem actions, and rely on the default credential provider chain.Answer
  3. C
    Instantiate the DynamoDB client and HTTP client inside the handler function to ensure the connection is closed and recreated for each invocation.
  4. D
    Store AWS access keys as environment variables and explicitly pass them when initializing the SDK clients in the code.
  5. E
    Associate the Lambda function with private VPC subnets without a NAT Gateway or VPC endpoint to restrict access and speed up DynamoDB write operations.

Answer

The correct actions are to initialize client instances outside the handler function to enable connection reuse, and to assign an IAM execution role with appropriate write permissions to DynamoDB.
Initializing client instances outside the handler allows AWS Lambda to reuse the execution context and the existing TCP connections across subsequent warm invocations, reducing latency. Using an IAM execution role provides temporary credentials automatically managed by the AWS SDK, following the principle of least privilege and avoiding hardcoded credentials.

Step-by-Step Solution

1
Analyze the performance bottleneck caused by connection setup overhead.
Determine that initializing the clients outside the handler is required.
The Lambda execution context persists across warm invocations, allowing global variables and connections to be reused.
2
Address the database access errors securely.
Configure an IAM execution role for the function and grant it permission to write to DynamoDB.
Relying on the default credential provider chain avoids storing credentials in the code or environment variables.

Key Concept

AWS Lambda execution context reuse and IAM execution roles.
Estimated Time:2m 0s
Rate this question