Skip to content

How do i force a fresh environment on a lambda function

0

my code starts getting problems after it is ran for around 20 times and until I refresh the environment manually by adding in the code again it will have issues . Is there a way to automate refreshing the environment to make sure everything is fresh on each run.

I have found an answer to question that looks close to this however lambda function failing does not seem to create a fresh environment .

asked 2 years ago3K views

1 Answer
2

Hello.

I don't think AWS officially announced the Lambda initialization timing.
My impression is that if you wait about 5 minutes and then re-run Lambda, it will run in an initialized environment.
https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html

I think it depends on the error and processing details, but I think it's a good idea to do something similar to initialization by freeing up memory or deleting the "/tmp" folder when Lambda processing ends.

For example, in Python, you can free up memory by releasing variables using "del".
https://docs.python.org/3/tutorial/datastructures.html#the-del-statement

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.