AWS documentation clearly states that:
It takes time to set up an execution context and do the necessary "bootstrapping", which adds some latency each time the Lambda function is invoked. You typically see this latency when a Lambda function is invoked for the first time or after it has been updated because AWS Lambda tries to reuse the execution context for subsequent invocations of the Lambda function.
After a Lambda function is executed, AWS Lambda maintains the execution context for some time in anticipation of another Lambda function invocation. In effect, the service freezes the execution context after a Lambda function completes, and thaws the context for reuse, if AWS Lambda chooses to reuse the context when the Lambda function is invoked again
In my main.go
file that holds a definition of my Handler
function I also have func init()
. My question is, does init()
execute each time Lambda is invoked?
If that is so, should I move variables that I initialize in init()
outside the function (make them global) in order to achieve re-use of execution context?