AWS Certified Developer – Associate (DVA-C02)Development with AWS ServicesMedium
A developer is building a serverless application that uses AWS Lambda to process images uploaded to an Amazon S3 bucket. The Lambda function needs to download the original image, resize it, and then upload the resized image back to S3. The image resizing library requires temporary disk space to store intermediate files during processing. Which of the following is the MOST efficient and secure way for the Lambda function to handle these temporary files?
- AStream the image data directly to the resizing library without saving to disk.
- BStore intermediate files directly in an S3 bucket.
- CUse the /tmp directory provided by Lambda's execution environment.
- DMount an Amazon EBS volume to the Lambda function.
Show answer & explanationAnswer & explanation
Correct answer: C. Use the /tmp directory provided by Lambda's execution environment.
The /tmp directory in the Lambda execution environment provides a secure, ephemeral storage location for temporary files. It is efficient because it's local storage, and its contents are automatically cleared after the function invocation, making it suitable for intermediate processing without persistent storage concerns.
Why the other options are wrong
- A. While streaming is efficient, the question explicitly states the resizing library 'requires temporary disk space', making direct streaming not fully applicable to the stated constraint.
- B. Storing intermediate files in S3 would incur additional latency and cost due to network I/O, making it less efficient for temporary local processing.
- D. EBS volumes cannot be directly mounted to AWS Lambda functions.
Lambda /tmp Directory
The /tmp directory in the AWS Lambda execution environment provides ephemeral, local disk space for temporary files during a function invocation.
- Local, ephemeral storage.
- Up to 512 MB (or more, configurable up to 10 GB with Ephemeral Storage).
- Contents are cleared after invocation.
Memory trick: For quick Lambda temp needs, /tmp always succeeds.