Skip to content

Commit bc34fea

Browse files
committed
fix(core): detect bundled SDK via version stamp
1 parent 630b777 commit bc34fea

2 files changed

Lines changed: 58 additions & 37 deletions

File tree

packages/aws-durable-execution-sdk-python/src/aws_durable_execution_sdk_python/lambda_service.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,9 @@
3838
logger = logging.getLogger(__name__)
3939

4040

41-
def _is_in_var_dir(module_file: str = __file__) -> bool:
42-
"""Return True if this SDK is installed under /var/lang/.
43-
44-
Lambda bundled Python runtimes install packages at
45-
/var/lang/lib/pythonX.Y/site-packages/.
46-
"""
47-
return module_file.startswith("/var/lang/")
41+
def _is_bundled(version: str) -> bool:
42+
"""True if the managed runtime stamped a +bundled label onto this install."""
43+
return version.endswith("+bundled")
4844

4945

5046
# region model
@@ -1218,7 +1214,7 @@ def initialize_client(cls) -> LambdaClient:
12181214
config=Config(
12191215
connect_timeout=5,
12201216
read_timeout=50,
1221-
user_agent_extra=f"aws-durable-execution-sdk-python/{__version__}{'-bundled' if _is_in_var_dir() else ''}",
1217+
user_agent_extra=f"aws-durable-execution-sdk-python/{__version__.removesuffix('+bundled')}{'-bundled' if _is_bundled(__version__) else ''}",
12221218
),
12231219
)
12241220
return cls(client=cls._cached_boto_client)

packages/aws-durable-execution-sdk-python/tests/lambda_service_test.py

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
TimestampConverter,
4141
WaitDetails,
4242
WaitOptions,
43-
_is_in_var_dir,
43+
_is_bundled,
4444
)
4545

4646

@@ -2226,14 +2226,14 @@ def test_lambda_client_initialize_client_no_endpoint(
22262226

22272227

22282228
@patch(
2229-
"aws_durable_execution_sdk_python.lambda_service._is_in_var_dir",
2229+
"aws_durable_execution_sdk_python.lambda_service._is_bundled",
22302230
return_value=True,
22312231
)
22322232
@patch("boto3.client")
22332233
def test_lambda_client_user_agent_runtime_bundled(
2234-
mock_boto_client, _mock_is_in_var_dir, reset_lambda_client_cache
2234+
mock_boto_client, _mock_is_bundled, reset_lambda_client_cache
22352235
):
2236-
"""user_agent_extra includes -bundled when SDK is in /var/lang/."""
2236+
"""user_agent_extra includes -bundled when the +bundled stamp is present."""
22372237
mock_client = Mock()
22382238
mock_boto_client.return_value = mock_client
22392239

@@ -2243,56 +2243,81 @@ def test_lambda_client_user_agent_runtime_bundled(
22432243
config = call_args[1]["config"]
22442244
assert (
22452245
config.user_agent_extra
2246-
== f"aws-durable-execution-sdk-python/{__version__}-bundled"
2246+
== f"aws-durable-execution-sdk-python/{__version__.split('+')[0]}-bundled"
22472247
)
22482248
assert isinstance(client, LambdaClient)
22492249

22502250

22512251
@patch(
2252-
"aws_durable_execution_sdk_python.lambda_service._is_in_var_dir",
2252+
"aws_durable_execution_sdk_python.lambda_service._is_bundled",
22532253
return_value=False,
22542254
)
22552255
@patch("boto3.client")
22562256
def test_lambda_client_user_agent_not_runtime_bundled(
2257-
mock_boto_client, _mock_is_in_var_dir, reset_lambda_client_cache
2257+
mock_boto_client, _mock_is_bundled, reset_lambda_client_cache
22582258
):
2259-
"""user_agent_extra omits -bundled when SDK is not in /var/lang."""
2259+
"""user_agent_extra omits -bundled when the +bundled stamp is absent."""
22602260
mock_client = Mock()
22612261
mock_boto_client.return_value = mock_client
22622262

22632263
client = LambdaClient.initialize_client()
22642264

22652265
call_args = mock_boto_client.call_args
22662266
config = call_args[1]["config"]
2267-
assert config.user_agent_extra == f"aws-durable-execution-sdk-python/{__version__}"
2267+
assert (
2268+
config.user_agent_extra
2269+
== f"aws-durable-execution-sdk-python/{__version__.split('+')[0]}"
2270+
)
22682271
assert isinstance(client, LambdaClient)
22692272

22702273

2274+
@patch("aws_durable_execution_sdk_python.lambda_service.__version__", "2.0.0+acme.1")
2275+
@patch("boto3.client")
2276+
def test_lambda_client_user_agent_preserves_local_version_label(
2277+
mock_boto_client, reset_lambda_client_cache
2278+
):
2279+
"""A non-bundled local version label is kept intact in the user agent."""
2280+
mock_boto_client.return_value = Mock()
2281+
2282+
LambdaClient.initialize_client()
2283+
2284+
config = mock_boto_client.call_args[1]["config"]
2285+
assert config.user_agent_extra == "aws-durable-execution-sdk-python/2.0.0+acme.1"
2286+
2287+
2288+
@patch("aws_durable_execution_sdk_python.lambda_service.__version__", "2.0.0+bundled")
2289+
@patch("boto3.client")
2290+
def test_lambda_client_user_agent_strips_bundled_suffix(
2291+
mock_boto_client, reset_lambda_client_cache
2292+
):
2293+
"""The +bundled stamp is stripped from the version and reported as -bundled."""
2294+
mock_boto_client.return_value = Mock()
2295+
2296+
LambdaClient.initialize_client()
2297+
2298+
config = mock_boto_client.call_args[1]["config"]
2299+
assert config.user_agent_extra == "aws-durable-execution-sdk-python/2.0.0-bundled"
2300+
2301+
22712302
@pytest.mark.parametrize(
2272-
"path,expected",
2303+
"version,expected",
22732304
[
2274-
# Lambda bundled runtime site-packages
2275-
(
2276-
"/var/lang/lib/python3.13/site-packages/aws_durable_execution_sdk_python/lambda_service.py",
2277-
True,
2278-
),
2279-
(
2280-
"/var/lang/lib/python3.12/site-packages/aws_durable_execution_sdk_python/lambda_service.py",
2281-
True,
2282-
),
2283-
# Customer deployment package
2284-
("/var/task/aws_durable_execution_sdk_python/lambda_service.py", False),
2285-
# Lambda Layer
2286-
("/opt/python/aws_durable_execution_sdk_python/lambda_service.py", False),
2287-
# Trailing-slash guard: /var/langsurprise must not match
2288-
("/var/langsurprise/lib/python3.13/site-packages/x.py", False),
2289-
# Local dev
2290-
("/Users/me/project/.venv/lib/python3.12/site-packages/x.py", False),
2305+
# Managed-runtime stamp
2306+
("1.7.0+bundled", True),
2307+
("1.7.0.post0+bundled", True),
2308+
# Public PyPI installs never carry the local label
2309+
("1.7.0", False),
2310+
("1.7.0.post0", False),
2311+
# A different local label must not match
2312+
("1.7.0+local", False),
2313+
# A label beginning with 'bundled' must not match, only the exact suffix
2314+
("1.7.0+bundleddebug", False),
2315+
("1.7.0+bundled.1", False),
22912316
("", False),
22922317
],
22932318
)
2294-
def test_is_in_var_dir(path, expected):
2295-
assert _is_in_var_dir(path) is expected
2319+
def test_is_bundled(version, expected):
2320+
assert _is_bundled(version) is expected
22962321

22972322

22982323
def test_lambda_client_checkpoint_with_non_none_client_token():

0 commit comments

Comments
 (0)