An analytics application utilizes an AWS Lambda function to generate daily reports. The function downloads several source files to the local ephemeral storage (`/tmp`), merges them, and uploads the final report to Amazon S3. The function is configured with of ephemeral storage. While initial test runs succeed, the function intermittently fails during peak hours with a `No space left on device` error, even though the source files for any single invocation never exceed in total. What is the root cause of this failure, and how should the developer resolve it?
- The execution context is being reused across invocations, causing files from previous runs to persist in the `/tmp` directory. The developer should modify the code to delete temporary files from `/tmp` before the function execution completes.Cevap
- BThe developer assumed that the ephemeral storage is automatically wiped by Lambda between warm starts. The developer should increase the Lambda function's execution timeout limit to allow the platform's automatic background garbage collector to clean up the directory.
- CThe Lambda function is deployed in a private VPC subnet without a NAT Gateway or VPC endpoint to access the Amazon S3 service. The developer should configure a NAT Gateway in the public subnet and update the route tables to allow the function to upload the files and free up storage.
- DThe Lambda function's execution role trust policy is missing the `lambda.amazonaws.com` service principal, preventing the function from writing log streams to CloudWatch and causing local write buffers to overflow. The developer should modify the trust policy to allow the service principal.
Cevap
The execution context is being reused across invocations, causing files from previous runs to persist in the `/tmp` directory. The developer should modify the code to delete temporary files from `/tmp` before the function execution completes.
The correct answer is the option explaining that the execution context is reused across invocations, which preserves files in the `/tmp` directory. To resolve the issue, the developer must explicitly delete the files before the invocation ends. AWS Lambda reuses execution environments to avoid cold start overhead. When an environment is reused, the state of the `/tmp` directory is maintained. If a function writes files to `/tmp` and does not clean them up, subsequent invocations in the same environment will find those files still present, leading to cumulative disk usage and eventual disk exhaustion.
Adım Adım Çözüm
Anahtar Kavram
AWS Lambda reuses its execution context (including the `/tmp` directory) across sequential invocations (warm starts). Developers must explicitly clean up any ephemeral storage files to prevent disk exhaustion over time.