-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Expected Behavior
The Lambda SDK client created by Durable SDK should be reused across warm starts - replay behavior. It's a performance issue - every invocation is slower than it needs to be. And over time, that adds up to real cost.
src/aws_durable_execution_sdk_python/lambda_service.py - LambdaClient.initialize_client()
Actual Behavior
I'm building an app with durable functions and noticed that every time a Lambda invocation happens, the boto3 client gets recreated. This is wasteful because the client does a lot of setup work (credential resolution, endpoint config, connection pooling, unzip botocore models and stuff) that could be reused.
I think we could cache the client at module level using a global variable. Lambda might reuses the same sandbox for warm starts, so the cached client would stick around. Credentials shouldn't be an issue either - boto3 handles refresh automatically, which is how all AWS SDKs work.
I tested this code and got these results for a 128MB Lambda:
from aws_durable_execution_sdk_python import DurableContext
from aws_durable_execution_sdk_python.config import Duration
from aws_durable_execution_sdk_python.execution import durable_execution
@durable_execution
def lambda_handler(event: dict, context: DurableContext) -> dict:
context.logger.info("Starting durable execution")
# Wait for 5 seconds
context.wait(Duration.from_seconds(5), name="wait_5_seconds")
print("Wait completed, execution finished")
return {
"status": "success",
"message": "Durable execution with wait completed",
}Creating new client
Duration: 183.866ms
Billed Duration: 184ms
Reusing the client
Duration: 102.735ms
Billed Duration: 103ms
Steps to Reproduce
Deploy the code above and test.
SDK Version
latest
Python Version
3.14
Is this a regression?
No
Last Working Version
No response
Additional Context
No response