An application contains an AWS Lambda function that retrieves configuration files from Amazon S3 and writes audit logs to Amazon DynamoDB. The function's latency is higher than expected due to client initialization and S3 downloads occurring on every invocation. Which two actions will optimize the performance of this function by leveraging execution context reuse? (Select TWO.)
- Initialize the AWS SDK clients for S3 and DynamoDB outside of the Lambda handler function.Answer
- Download and store the configuration files in the local /tmp directory to reuse them across subsequent invocations.Answer
- CInstantiate the S3 and DynamoDB SDK clients inside the handler function to guarantee fresh connections for each invocation.
- DHardcode the AWS access key and secret access key in the SDK client configuration to reduce credential retrieval time.
- EConfigure the Lambda function to run inside a private VPC subnet without a NAT Gateway or VPC endpoints to ensure isolated database routing.
Answer
To optimize the Lambda function using execution context reuse, the developer should initialize the S3 and DynamoDB SDK clients outside of the handler function, and download and store the configuration files in the local /tmp directory.
Initializing AWS SDK clients outside the handler method enables the execution environment to reuse the connection pool across warm invocations. Additionally, caching files in the local /tmp directory allows subsequent invocations to read the configurations from local storage instead of performing network requests to Amazon S3.
Step-by-Step Solution
Key Concept
Execution context reuse and temporary storage cache optimization in AWS Lambda
Estimated Time:1m 0s