AWS Certified Developer – Associate (DVA-C02)Development with AWS ServicesMedium
A developer is writing an AWS Lambda function that processes images uploaded to an Amazon S3 bucket. The Lambda function needs to perform image resizing, apply watermarks, and then store the modified images in another S3 bucket. This process involves downloading the original image, processing it locally within Lambda, and then uploading the result. Which of the following is the most efficient way for the Lambda function to handle the temporary storage of image files during processing?
- AStore the temporary files in an Amazon EFS mount point attached to the Lambda function.
- BUpload intermediate processing results to a separate 'staging' S3 bucket.
- CStream the image data directly to an Amazon Kinesis Data Stream for processing.
- DUtilize the `/tmp` directory provided by the Lambda execution environment.
Show answer & explanationAnswer & explanation
Correct answer: D. Utilize the `/tmp` directory provided by the Lambda execution environment.
The `/tmp` directory in the Lambda execution environment provides ephemeral, local storage that is accessible during the function's invocation. It's suitable for temporary files like images being processed, up to 512 MB (or more with larger ephemeral storage configuration).
Why the other options are wrong
- A. Amazon EFS is for persistent, shared file storage across multiple Lambda invocations or functions, which is an overkill for temporary, per-invocation files and adds latency/cost.
- B. Using a separate S3 bucket for intermediate results would incur additional S3 costs, network latency, and complexity for temporary files.
- C. Amazon Kinesis Data Streams are for streaming data, not for temporary file storage during image processing within a Lambda function.
Lambda /tmp Directory
A temporary, ephemeral file system available to an AWS Lambda function during its invocation, suitable for storing temporary data.
- Provides up to 512 MB of storage by default (configurable up to 10 GB).
- Data in `/tmp` is lost after the invocation completes.
- Accessible within the Lambda execution environment for local file operations.
Memory trick: When Lambda needs to 'dump' temporary data, `/tmp` is the best spot for a quick jump.