Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Dynamo DB connection during run time #787

Answered by ran-isenberg
abel-dan asked this question in Q&A
Discussion options

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?

image

Disclaimer : - I am pretty new to Python and Serverless :)

You must be logged in to vote

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...

Replies: 1 comment

Comment options

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-to-write-aws-lambda-functions-with-architecture-layers

You must be logged in to vote
0 replies
Answer selected by ran-isenberg
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /