A developer is writing an AWS Lambda function that must download a static reference file from Amazon S3 and reuse it across multiple invocations. The developer wants to minimize execution time and reduce the number of calls to Amazon S3.
Which two actions should the developer take to accomplish this?
- Declare the Amazon S3 client and configuration variables outside of the handler function.Cevap
- Store the downloaded reference file in the local /tmp directory of the execution environment.Cevap
- CUpdate the Lambda function's environment variables dynamically at runtime to store the file's content.
- DEmbed the AWS access key and secret key directly in the Amazon S3 client initialization code to speed up authentication.
- EDeploy the Lambda function within a private VPC subnet with no NAT gateway to enable faster access to local storage.
Cevap
To optimize execution time and reuse files across invocations, declare the client and variables outside of the handler function, and store the downloaded file in the local /tmp directory.
Declaring the Amazon S3 client outside of the handler ensures it is initialized once during cold start, and storing the downloaded file in the /tmp directory leverages ephemeral storage that persists across warm starts. Together, these steps significantly reduce execution time and avoid redundant calls to S3.
Adım Adım Çözüm
Anahtar Kavram
AWS Lambda execution context lifecycle, initialization phase, and local ephemeral storage usage.