Dynamo DB connection during run time #787
-
AWS documentation recommends that AWS service clients should be instantiated in the initialization code, not in the handler. But I could see that we are taking new connection during run time . Below snap shot of dynamo_dal_handler shown below. Will this affect the performance? Disclaimer : - I am pretty new to Python and Serverless :) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
hey @abel-dan , thanks for asking a question and welcome to the amazing world of serverless :) As you can see, there's a decorator in line 23 for cache and class itself is a singleton. That means that we create only one client class (until the cache expires) and reuse it as long as the function is warm for new invocations. |
Beta Was this translation helpful? Give feedback.
hey @abel-dan , thanks for asking a question and welcome to the amazing world of serverless :)
As you can see, there's a decorator in line 23 for cache and class itself is a singleton. That means that we create only one client class (until the cache expires) and reuse it as long as the function is warm for new invocations.
It's not set in stone to init that connection as AWS recommends, i did a lazy init here and afterwards its warm for new invocation. I dont think there's a difference in performance. TBH, putting way too things that init during the first run isnt that useful in my view and breaks the architectural layers model i discuss at : https://www.ranthebuilder.cloud/post/learn-how…