I have been reading AWS guide regarding "Best Practices for Working with AWS Lambda Functions", I have understood and implemented most of it, but, I am having trouble implementing this part:
Take advantage of Execution Context reuse to improve the performance of your function. Make sure any externalized configuration or dependencies that your code retrieves are stored and referenced locally after initial execution. Limit the re-initialization of variables/objects on every invocation. Instead use static initialization/constructor, global/static variables and singletons. Keep alive and reuse connections (HTTP, database, etc.) that were established during a previous invocation.
In my Lambda function I have connection to a specific bucket of S3 service where I read particular data, and a connection to specific bucket of S3 service where I write processed data.
I am constantly re-opening connection to these buckets and I was wondering how can I write code in Go programming language so that I open the connections only once and re-use them?
Essentially my question is, when Lambda function invoked for the first time, which part of the code gets to be executed first and does not execute every other time when that same Lambda function gets invoked.
I've also read somewhere that this is what is referred to as "Pre-Handler Code".
Any help would be appreciated. Thank you in advance!