cloud resource_limit ai_generated true

OSError: [Errno 28] No space left on device in AWS Lambda /tmp

ID: cloud/aws-lambda-tmp-storage-512mb

Also available as: JSON · Markdown
88%Fix Rate
90%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
any active

Root Cause

Lambda /tmp is limited to 512MB by default (expandable to 10GB since 2022). But /tmp persists across warm invocations! Previous invocation's temp files eat into the next invocation's quota.

generic

Workarounds

  1. 92% success Clean /tmp at the start of each invocation
    import shutil, os; [os.remove(os.path.join('/tmp', f)) for f in os.listdir('/tmp')]
  2. 95% success Configure ephemeral storage up to 10GB in Lambda config
    aws lambda update-function-configuration --function-name my-func --ephemeral-storage '{"Size": 5120}'
  3. 88% success Use S3 or EFS for large file processing instead of /tmp
    Mount EFS filesystem or stream data to/from S3 instead of downloading to /tmp

Dead Ends

Common approaches that don't work:

  1. Increase Lambda memory to get more /tmp space 92% fail

    Lambda memory and /tmp storage are independent. More memory does NOT increase /tmp. You must configure ephemeral storage separately.

  2. Write temp files and assume they're cleaned up between invocations 90% fail

    /tmp is NOT cleaned between warm invocations. Files from previous invocations persist and accumulate.