Jon
Jon

Reputation: 6265

What happens to leftover files created by lambda function

If I write a file to disk inside of a lambda function, what happens to it after I'm done with the lambda function. Do I have to explicitly tell it to remove, or will amazon automatically delete everything after the function finishes running?

Upvotes: 2

Views: 1453

Answers (1)

Xavier Hutchinson
Xavier Hutchinson

Reputation: 2227

Lambda functions that you execute on AWS run within an isolated space called a container, which is provisioned just for you and that function. AWS may not clean up this container immediately for the purpose of making subsequent executions of your lambda function faster (as the container is already provisioned).

When your Lambda function is not executed for "an amount of time" the container will be cleaned up by AWS. If you publish a revision of your code then old containers are cleaned up and a new one is provisioned for your Lambda function on next execution.

What is important to keep in mind is that the files you mention and any variables you declare outside of the handler code will still be present on subsequent executions. The same goes for your /tmp files

Knowing that this is the case you should also consider redesigning your code to ensure a clean exit (even under a failure condition) if "left-overs" from past executions could cause you some conflict.

It's also important to make sure that you never assume a container will still exist on next execution.

You can check out some official documentation on this here: http://docs.aws.amazon.com/lambda/latest/dg/lambda-introduction.html

I hope this helps!

Upvotes: 4

Related Questions