Skip to content

[Bug]: boto3 client recreated on every invocation #249

@leandrodamascena

Description

@leandrodamascena

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
Image

Reusing the client

Duration: 102.735ms
Billed Duration: 103ms
Image

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

Metadata

Metadata

Labels

bugSomething isn't working

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions