1

I am using NodeJS6.10 in my Lambda functions. My function instantiates an object as part of the code and in my object's constructor, I am writing to the log file.

It seems that subsequent invocations of the same Lambda function don't invoke the object's constructor. It is as if it is cached somehow. I only see the log from the constructor once.

Every now and then, the cache seems to expire and the following Lambda call WILL invoke the object's constructor.

Is this behaviour normal? How can I control such caching?

Thanks

3
  • Can I see a code example? Lambdas on first run are cold and instantiate everything if another request hits that same Lambda and it has global or static variables I believe they will still be in memory. Commented Dec 28, 2018 at 15:40
  • Unfortunately I cannot share the code, but I can say that the object in question is indeed a global one... Will do some readings on this. Thanks Commented Dec 28, 2018 at 15:52
  • Thanks to your comments, I found this: medium.com/tensult/… Commented Dec 28, 2018 at 16:34

1 Answer 1

2

Turns out that the Lambda has its own cache for global variables. Since the objects in question were created in the global scope, they get served from the Lambda cache and the constructor is not invoked.

Check this out: https://medium.com/tensult/aws-lambda-function-issues-with-global-variables-eb5785d4b876

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.