AWS lambda - Release /tmp storage after each execution AWS lambda - Release /tmp storage after each execution python python

AWS lambda - Release /tmp storage after each execution


Yes, lambda being a managed service; they do reuse the same underlying resource if the lambda is getting invoked repeatedly. This was a production problem we faced and fixed by deleting the /tmp. On a separate note AWS should mention this in their FAQs.

if os.path.exists(tmp_file_path):        os.remove(tmp_file_path)        print("Removed the file %s" % tmp_file_path)     else:    print("Sorry, file %s does not exist." % tmp_file_path)


Containers are often reused, but not concurrently. Clean up your temp directory when the function finishes and see if issue resolves.


I tried to replicate this issue using lambdash, a great function to test out commands in your "dev" account. It allows you to run arbitrary UNIX commands in the Lambda environment.

I ran this command repeatedly, and did not see the issue appear. Note: The commands are not actually in the deployed code so this test does not fully replicate the potential issue.

lambdash "echo Checking:;file /tmp/nullfile;rm -f /tmp/nullfile;df -h /tmp;dd if=/dev/zero bs=1024 count=88888 >> /tmp/nullfile; echo ==========;df -h /tmp"