John M
John M

Reputation: 197

AWS lambda function scaling and /tmp directory

I am trying to understand how to efficiently use the /tmp directory, but I am a bit puzzled as to whether a new /tmp directory will be given for each invocation.

Say for example I have a Lambda function and hammer it with 100 calls - I would think that if I did this in quick succession, the invocation will be reused. Now, if I decide to hammer the function with another 100 calls (while the first 100 is still processing), and assuming AWS scales my function by invoking another instance of my function, will this new invocation instance use the the same /tmp directory or will I get another /tmp?

I hope my question is clear! Essentially, I'd like to know if when AWS scales my lambda function like AWS Lambda function scaling - AWS Lambda, so I get a new /tmp per invocation.

Upvotes: 2

Views: 1430

Answers (1)

John Rotenstein
John Rotenstein

Reputation: 269861

The /tmp/ directory is associated with the environment. If the environment is reused, then it is the same /tmp/ directory.

If Lambda invocations overlap, then multiple environments will be created. If none of the invocations overlap, then the same environment will be used for each execution, so it will have the same /tmp/ directory.

In general:

  • Delete files created in the /tmp/ directory before exiting the Lambda function to avoid running out of space (512MB limit)
  • However, you can keep files in /tmp/ if you want them kept for future executions, such as caching configuration files that are reused

Here is a great series of articles about AWS Lambda function execution:

Upvotes: 3

Related Questions