Skip to content

Add Lambda bundled runtime useragent header#379

Merged
yaythomas merged 2 commits intomainfrom
bundled-runtime-useragent
May 6, 2026
Merged

Add Lambda bundled runtime useragent header#379
yaythomas merged 2 commits intomainfrom
bundled-runtime-useragent

Conversation

@nvasiu
Copy link
Copy Markdown
Contributor

@nvasiu nvasiu commented May 5, 2026

  • Add boolean that checks if the SDK is running in a path that matches the path used within the Lambda bundled runtime.
  • Update the useragent header string to include "-bundledruntime" if the above boolean is true.

Issue #, if available:

N/A

Description of changes:

Note: we are waiting to confirm the Lambda bundled runtime SDK path. Do NOT merge this PR until we get confirmation.

Updating the UserAgent header string to indicate whether the SDK is being run within the Lambda bundled runtime.

  • A new boolean checks if the SDK's current path matches the path where it would be installed in the Lambda bundled runtime.
  • If the above boolean is true, the string inserted into the UserAgent header will include "-bundled". Example:
    aws-durable-execution-sdk-python/{version}-bundled

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@nvasiu nvasiu force-pushed the bundled-runtime-useragent branch 2 times, most recently from 3fc3f51 to 265a5a1 Compare May 5, 2026 18:30
connect_timeout=5,
read_timeout=50,
user_agent_extra=f"aws-durable-execution-sdk-python/{__version__}",
user_agent_extra=f"aws-durable-execution-sdk-python{'-bundledruntime' if _IS_RUNTIME_BUNDLED else ''}/{__version__}",
Copy link
Copy Markdown
Contributor

@zhongkechen zhongkechen May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this -bundledruntime be part of the sdk name or part of the version?

And -bundledruntime sounds weird like the runtime is bundled in SDK. Why don't we simply used -bundled?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense as part of the name, because the bundled runtime doesn't use a special SDK version.

I can make an update to just say "-bundled".

Copy link
Copy Markdown
Contributor

@leandrodamascena leandrodamascena May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry to jump into the conversation, but I would add the AWS_EXECUTION_ENV environment variable here - if not set assume "NA" for example. While this SDK is 100% focused on Lambda and only works with the specific payload sent to Lambda, you never know how creatively customers are using it. In Powertools for AWS Lambda, we identified clients using it on a wide variety of platforms other than Lambda.

But of course, it's just an idea, and I don't know if this affects how you consume this string in the backend.

Copy link
Copy Markdown
Contributor

@yaythomas yaythomas May 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree re the bundling effectively being a version variant. something like aws-durable-execution-sdk-python/v.1.2.3-bundled

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

re AWS_EXECUTION_ENV

if exists could be:

# bring your own
aws-durable-execution-sdk-js/1.2.3#nodejs24.x

# bundled
aws-durable-execution-sdk-js/1.2.3-bundled#runtime-nodejs24.x

# no execution env variable, use current interpreter version
aws-durable-execution-sdk-js/1.2.3-bundled#node-v20.19.0

@nvasiu nvasiu force-pushed the bundled-runtime-useragent branch 2 times, most recently from fffdbb5 to c7da73c Compare May 5, 2026 22:08
OperationPayload: TypeAlias = str
TimeoutSeconds: TypeAlias = int

_IS_RUNTIME_BUNDLED: bool = os.path.dirname(__file__).startswith("/var/lang")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be /var/lang/?

/var/langsurprise/ will return true here.

also, os.path.dirname isn't adding much here, might as well just use __file__.startswith("/var/lang/")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also, var name should prob be _IS_IN_VAR_DIR.

but the __file__ lookup is also just a lookup in the global namespace, so at the module level this isn't winning much, might as well have the check in the initialize check and then unit test on the actual file name too.

   def _is_in_var_dir(module_file: str = __file__) -> bool:
       """Return True if this SDK is installed under /var/lang/.

       Lambda BYOL Python runtimes install bundled packages at
       /var/lang/lib/pythonX.Y/site-packages/ 
       """
       return module_file.startswith("/var/lang/")

Comment thread tests/lambda_service_test.py Outdated


@patch("aws_durable_execution_sdk_python.lambda_service._IS_RUNTIME_BUNDLED", True)
@patch.dict("os.environ", {}, clear=True)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this actually do anything? there aren't any env vars under test?

@yaythomas
Copy link
Copy Markdown
Contributor

Reference: the similar change in ts/js aws/aws-durable-execution-sdk-js#527

nvasiu and others added 2 commits May 6, 2026 16:24
- Detect whether the SDK is installed under the Lambda
 runtime path. If so, update the UserAgent header string.
@yaythomas yaythomas force-pushed the bundled-runtime-useragent branch from 69685d2 to 596166c Compare May 6, 2026 23:25
@yaythomas yaythomas dismissed their stale review May 6, 2026 23:39

made changes myself

@yaythomas yaythomas merged commit 87586bd into main May 6, 2026
66 of 68 checks passed
@yaythomas yaythomas deleted the bundled-runtime-useragent branch May 6, 2026 23:39
connect_timeout=5,
read_timeout=50,
user_agent_extra=f"aws-durable-execution-sdk-python/{__version__}",
user_agent_extra=f"aws-durable-execution-sdk-python/{__version__}{'-bundled' if _is_in_var_dir() else ''}",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like -runtime might be more accurate (since it's bundled in the runtime)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants