I got the following error when I ran python code on AWS lambda.
"errorMessage": "[Errno 17] File exists: '/tmp/testdir/'"
It occurs on the line os.makedirs('/tmp/testdir/')
.
Before I didn't have this kind of error. Does this mean Lambda function preserves tmp directory?
Should I clean tmp directory everytime?
CodePudding user response:
Yes, the content of the Lambda diskspace at /tmp
may be available to subsequent Lambda invocations (these are so-called 'warm start' invocations).
See Understanding Container Reuse.
You can clean up the /tmp
folder before existing your Lambda function or you could use the following code to safely create the folder, ignoring the fact that it may already exist:
os.makedirs('/tmp/testdir/', exist_ok=True)