Add Lambda bundled runtime useragent header#379
Conversation
3fc3f51 to
265a5a1
Compare
| 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__}", |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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".
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
agree re the bundling effectively being a version variant. something like aws-durable-execution-sdk-python/v.1.2.3-bundled
There was a problem hiding this comment.
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
fffdbb5 to
c7da73c
Compare
| OperationPayload: TypeAlias = str | ||
| TimeoutSeconds: TypeAlias = int | ||
|
|
||
| _IS_RUNTIME_BUNDLED: bool = os.path.dirname(__file__).startswith("/var/lang") |
There was a problem hiding this comment.
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/")
There was a problem hiding this comment.
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/")
|
|
||
|
|
||
| @patch("aws_durable_execution_sdk_python.lambda_service._IS_RUNTIME_BUNDLED", True) | ||
| @patch.dict("os.environ", {}, clear=True) |
There was a problem hiding this comment.
does this actually do anything? there aren't any env vars under test?
|
Reference: the similar change in ts/js aws/aws-durable-execution-sdk-js#527 |
- Detect whether the SDK is installed under the Lambda runtime path. If so, update the UserAgent header string.
69685d2 to
596166c
Compare
| 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 ''}", |
There was a problem hiding this comment.
I feel like -runtime might be more accurate (since it's bundled in the runtime)
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.
aws-durable-execution-sdk-python/{version}-bundledBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.