-
Notifications
You must be signed in to change notification settings - Fork 13
refactor: reuse the Lambda client #251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
18067a1
b73afbd
61fd2e1
c75e913
6d85a31
07b1dbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -937,19 +937,33 @@ def get_execution_state( | |
| class LambdaClient(DurableServiceClient): | ||
| """Persist durable operations to the Lambda Durable Function APIs.""" | ||
|
|
||
| boto3_instance: LambdaClient | None = None | ||
|
|
||
| def __init__(self, client: Any) -> None: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for a different day, currently since we're only using 2 methods, might be an idea to create a protocol:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we should consider using I'm happy to explore this in a follow-up PR if you're open to it. But pls let me know if you want me to add this class now, it's easy.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure how "standard" and yes, adding it as dev dependency is reasonable :-) |
||
| self.client = client | ||
|
|
||
| @staticmethod | ||
| def initialize_client() -> LambdaClient: | ||
| client = boto3.client( | ||
| "lambda", | ||
| config=Config( | ||
| connect_timeout=5, | ||
| read_timeout=50, | ||
| ), | ||
| ) | ||
| return LambdaClient(client=client) | ||
| @classmethod | ||
| def initialize_client(cls) -> LambdaClient: | ||
yaythomas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Initialize or return cached Lambda client. | ||
|
|
||
| Implements lazy initialization with class-level caching to optimize | ||
| Lambda warm starts. The client is created once and reused across | ||
| invocations, avoiding repeated credential resolution and connection | ||
| pool setup. | ||
|
|
||
| Returns: | ||
| LambdaClient: The cached or newly created Lambda client. | ||
| """ | ||
| if cls.boto3_instance is None: | ||
| client = boto3.client( | ||
| "lambda", | ||
| config=Config( | ||
| connect_timeout=5, | ||
| read_timeout=50, | ||
| ), | ||
| ) | ||
| cls.boto3_instance = cls(client=client) | ||
| return cls.boto3_instance | ||
|
|
||
| def checkpoint( | ||
| self, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.