Question

Difficulty: MediumServerless Development with AWS Lambda

A developer has implemented an AWS Lambda function that processes PDF documents uploaded to an Amazon S3 bucket. The function downloads each PDF to the local `/tmp` directory, extracts metadata, and updates a database. During high-volume load testing, several invocations fail with a 'No space left on device' error. Additionally, the developer observes that PDF files from previous invocations occasionally persist and interfere with current executions. Which combination of actions should the developer take to resolve these issues? (Select two.)

  1. Programmatically delete the downloaded PDF files from the `/tmp` directory before the function invocation completes.Answer
  2. Increase the ephemeral storage (`/tmp`) configuration of the Lambda function to support larger file sizes.Answer
  3. C
    Configure Provisioned Concurrency for the Lambda function to guarantee that a new execution environment is initialized for every invocation.
  4. D
    Save the downloaded PDF files as global variables in the execution context instead of writing them to the `/tmp` directory.
  5. E
    Deploy the Lambda function inside a private subnet and configure an Amazon S3 Gateway VPC Endpoint to access the bucket.

Answer

To resolve the issues, the developer must programmatically delete the downloaded files from the local directory before execution completes, and increase the ephemeral storage configuration of the Lambda function.
The correct combination of actions involves programmatically deleting files from the local directory at the end of each invocation and increasing the function's configured ephemeral storage. Programmatic deletion ensures that files do not accumulate over multiple invocations that share the same warm execution environment, resolving both the data leakage and cumulative disk space consumption issues. Increasing the ephemeral storage configuration allows the function to use more than the default 512 MB of local storage to process larger files.

Step-by-Step Solution

1
Analyze how AWS Lambda handles execution environment reuse and the local filesystem.
The local filesystem directory is shared across consecutive invocations that run in the same container instance.
Files written to local storage persist between invocations unless programmatically deleted, which can cause disk space exhaustion and data contamination.
2
Address the data leakage and file persistence issue.
Implement code to clean up downloaded files from the local directory before returning a response.
Explicit cleanup ensures that subsequent invocations reusing the execution environment start with a clean local directory.
3
Address the disk space limit issue.
Modify the ephemeral storage configuration in the Lambda function settings to allocate more storage.
The default size of the local directory is 512 MB, which might be insufficient for larger or concurrent files. Increasing this configuration allows up to 10 GB of storage.

Key Concept

Understanding AWS Lambda execution context reuse and configuring ephemeral storage.
Rate this question