Skip to content

Commit 0969c71

Browse files
chore(sdk): use public boto3 Lambda client (#177)
* chore: remove internal lambda client * chore: remove internal lambda client * chore: making hatch happy
1 parent d99e230 commit 0969c71

File tree

11 files changed

+37
-7961
lines changed

11 files changed

+37
-7961
lines changed

.github/model/lambda.json

Lines changed: 0 additions & 7864 deletions
This file was deleted.

.github/workflows/deploy-examples.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@ jobs:
6060
role-session-name: pythonTestingLibraryGitHubIntegrationTest
6161
aws-region: ${{ env.AWS_REGION }}
6262

63-
- name: Install custom Lambda model
64-
run: |
65-
aws configure add-model --service-model file://.github/model/lambda.json --service-name lambda
66-
6763
- name: Install Hatch
6864
run: pip install hatch
6965

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ classifiers = [
2222
"Programming Language :: Python :: Implementation :: PyPy",
2323
]
2424
dependencies = [
25-
"boto3>=1.40.30",
25+
"boto3>=1.42.1",
2626
"requests>=2.25.0",
2727
"aws_durable_execution_sdk_python>=1.0.0",
2828
]
@@ -59,7 +59,7 @@ dependencies = [
5959
"pytest",
6060
"pytest-cov",
6161
"ruff",
62-
"aws_durable_execution_sdk_python @ {env:AWS_DURABLE_SDK_URL:git+ssh://[email protected]/aws/aws-durable-execution-sdk-python.git}",
62+
"aws_durable_execution_sdk_python>=1.0.0",
6363
]
6464

6565
[tool.hatch.envs.test.scripts]
@@ -72,7 +72,7 @@ cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src/aw
7272
dependencies = [
7373
"boto3",
7474
"PyYAML",
75-
"aws_durable_execution_sdk_python @ {env:AWS_DURABLE_SDK_URL:git+ssh://[email protected]/aws/aws-durable-execution-sdk-python.git}",
75+
"aws_durable_execution_sdk_python>=1.0.0",
7676
]
7777
[tool.hatch.envs.examples.scripts]
7878
cli = "python examples/cli.py {args}"

src/aws_durable_execution_sdk_python_testing/cli.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def get_durable_execution_history_command(self, args: argparse.Namespace) -> int
458458
def _create_boto3_client(
459459
self, endpoint_url: str | None = None, region_name: str | None = None
460460
) -> Any:
461-
"""Create boto3 client for lambdainternal service.
461+
"""Create boto3 client for Lambda service.
462462
463463
Args:
464464
endpoint_url: Optional endpoint URL override
@@ -471,18 +471,13 @@ def _create_boto3_client(
471471
Exception: If client creation fails
472472
"""
473473
try:
474-
# Set up AWS data path for boto models
475-
package_path = os.path.dirname(aws_durable_execution_sdk_python.__file__)
476-
data_path = f"{package_path}/botocore/data"
477-
os.environ["AWS_DATA_PATH"] = data_path
478-
479474
# Use provided values or fall back to config
480475
final_endpoint = endpoint_url or self.config.local_runner_endpoint
481476
final_region = region_name or self.config.local_runner_region
482477

483478
# Create client with local endpoint - no AWS access keys required
484479
return boto3.client(
485-
"lambdainternal",
480+
"lambda",
486481
endpoint_url=final_endpoint,
487482
region_name=final_region,
488483
)

src/aws_durable_execution_sdk_python_testing/invoker.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,7 @@ def __init__(self, lambda_client: Any) -> None:
136136
def create(endpoint_url: str, region_name: str) -> LambdaInvoker:
137137
"""Create with the boto lambda client."""
138138
invoker = LambdaInvoker(
139-
boto3.client(
140-
"lambdainternal", endpoint_url=endpoint_url, region_name=region_name
141-
)
139+
boto3.client("lambda", endpoint_url=endpoint_url, region_name=region_name)
142140
)
143141
invoker._current_endpoint = endpoint_url
144142
invoker._endpoint_clients[endpoint_url] = invoker.lambda_client
@@ -150,7 +148,7 @@ def update_endpoint(self, endpoint_url: str, region_name: str) -> None:
150148
with self._lock:
151149
if endpoint_url not in self._endpoint_clients:
152150
self._endpoint_clients[endpoint_url] = boto3.client(
153-
"lambdainternal", endpoint_url=endpoint_url, region_name=region_name
151+
"lambda", endpoint_url=endpoint_url, region_name=region_name
154152
)
155153
self.lambda_client = self._endpoint_clients[endpoint_url]
156154
self._current_endpoint = endpoint_url
@@ -166,7 +164,7 @@ def _get_client_for_execution(
166164
if lambda_endpoint:
167165
if lambda_endpoint not in self._endpoint_clients:
168166
self._endpoint_clients[lambda_endpoint] = boto3.client(
169-
"lambdainternal",
167+
"lambda",
170168
endpoint_url=lambda_endpoint,
171169
region_name=region_name or "us-east-1",
172170
)

src/aws_durable_execution_sdk_python_testing/runner.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,7 @@ def wait_for_callback(
698698

699699
# Timeout reached
700700
elapsed = time.time() - start_time
701-
msg = (
702-
f"Callback did not available within {timeout}s "
703-
f"(elapsed: {elapsed:.1f}s."
704-
)
701+
msg = f"Callback did not available within {timeout}s (elapsed: {elapsed:.1f}s."
705702
raise TimeoutError(msg)
706703

707704

@@ -850,26 +847,20 @@ def stop(self) -> None:
850847
self._executor = None
851848

852849
def _create_boto3_client(self) -> Any:
853-
"""Create boto3 client for lambdainternal service.
850+
"""Create boto3 client for Lambda service.
854851
855-
Configures AWS data path and creates a boto3 client with the
856-
local runner endpoint and region from configuration.
852+
Creates a boto3 client with the local runner endpoint and region from configuration.
857853
858854
Returns:
859-
Configured boto3 client for lambdainternal service
855+
Configured boto3 client for Lambda service
860856
861857
Raises:
862858
Exception: If client creation fails - exceptions propagate naturally
863859
for CLI to handle as general Exception
864860
"""
865-
# Set up AWS data path for boto models
866-
package_path = os.path.dirname(aws_durable_execution_sdk_python.__file__)
867-
data_path = f"{package_path}/botocore/data"
868-
os.environ["AWS_DATA_PATH"] = data_path
869-
870861
# Create client with Lambda endpoint configuration
871862
return boto3.client(
872-
"lambdainternal",
863+
"lambda",
873864
endpoint_url=self._config.lambda_endpoint,
874865
region_name=self._config.local_runner_region,
875866
)
@@ -904,14 +895,9 @@ def __init__(
904895
self.lambda_endpoint = lambda_endpoint
905896
self.poll_interval = poll_interval
906897

907-
# Set up AWS data path for custom boto models (durable execution fields)
908-
package_path = os.path.dirname(aws_durable_execution_sdk_python.__file__)
909-
data_path = f"{package_path}/botocore/data"
910-
os.environ["AWS_DATA_PATH"] = data_path
911-
912898
client_config = boto3.session.Config(parameter_validation=False)
913899
self.lambda_client = boto3.client(
914-
"lambdainternal",
900+
"lambda",
915901
endpoint_url=lambda_endpoint,
916902
region_name=region,
917903
config=client_config,
@@ -1154,10 +1140,7 @@ def wait_for_callback(
11541140

11551141
# Timeout reached
11561142
elapsed = time.time() - start_time
1157-
msg = (
1158-
f"Callback did not available within {timeout}s "
1159-
f"(elapsed: {elapsed:.1f}s."
1160-
)
1143+
msg = f"Callback did not available within {timeout}s (elapsed: {elapsed:.1f}s."
11611144
raise TimeoutError(msg)
11621145

11631146
def _fetch_execution_history(

src/aws_durable_execution_sdk_python_testing/web/serialization.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,10 @@ def create(cls, operation_name: str) -> AwsRestJsonSerializer:
110110
InvalidParameterValueException: If serializer creation fails
111111
"""
112112
try:
113-
package_path = os.path.dirname(aws_durable_execution_sdk_python.__file__)
114-
data_path = f"{package_path}/botocore/data"
115-
116113
# Load service model
117-
os.environ["AWS_DATA_PATH"] = data_path
118114
loader = botocore.loaders.Loader()
119-
loader.search_paths.append(data_path)
120115

121-
raw_model = loader.load_service_model("lambdainternal", "service-2")
116+
raw_model = loader.load_service_model("lambda", "service-2")
122117
service_model = ServiceModel(raw_model)
123118

124119
# Create serializer (rest-json protocol)
@@ -190,15 +185,10 @@ def create(cls, operation_name: str) -> AwsRestJsonDeserializer:
190185
InvalidParameterValueException: If deserializer creation fails
191186
"""
192187
try:
193-
package_path = os.path.dirname(aws_durable_execution_sdk_python.__file__)
194-
data_path = f"{package_path}/botocore/data"
195-
196188
# Load service model
197-
os.environ["AWS_DATA_PATH"] = data_path
198189
loader = botocore.loaders.Loader()
199-
loader.search_paths.append(data_path)
200190

201-
raw_model = loader.load_service_model("lambdainternal", "service-2")
191+
raw_model = loader.load_service_model("lambda", "service-2")
202192
service_model = ServiceModel(raw_model)
203193

204194
# Create parser (rest-json protocol)

tests/cli_test.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -985,29 +985,19 @@ def test_get_durable_execution_history_command_handles_connection_error() -> Non
985985
assert exit_code == 1
986986

987987

988-
def test_create_boto3_client_sets_up_aws_data_path() -> None:
989-
"""Test that _create_boto3_client sets up AWS data path correctly."""
988+
def test_create_boto3_client_creates_client_correctly() -> None:
989+
"""Test that _create_boto3_client creates boto3 client correctly."""
990990
app = CliApp()
991991

992992
with patch("boto3.client") as mock_boto3_client:
993-
with patch("os.environ") as mock_environ:
994-
with patch("os.path.dirname") as mock_dirname:
995-
mock_dirname.return_value = "/path/to/aws_durable_execution_sdk_python"
993+
app._create_boto3_client() # noqa: SLF001
996994

997-
app._create_boto3_client() # noqa: SLF001
998-
999-
# Verify AWS_DATA_PATH is set
1000-
mock_environ.__setitem__.assert_called_with(
1001-
"AWS_DATA_PATH",
1002-
"/path/to/aws_durable_execution_sdk_python/botocore/data",
1003-
)
1004-
1005-
# Verify boto3 client is created with correct parameters
1006-
mock_boto3_client.assert_called_once_with(
1007-
"lambdainternal",
1008-
endpoint_url=app.config.local_runner_endpoint,
1009-
region_name=app.config.local_runner_region,
1010-
)
995+
# Verify boto3 client is created with correct parameters
996+
mock_boto3_client.assert_called_once_with(
997+
"lambda",
998+
endpoint_url=app.config.local_runner_endpoint,
999+
region_name=app.config.local_runner_region,
1000+
)
10111001

10121002

10131003
def test_create_boto3_client_handles_creation_failure() -> None:

tests/invoker_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def test_lambda_invoker_create():
121121
assert isinstance(invoker, LambdaInvoker)
122122
assert invoker.lambda_client is mock_client
123123
mock_boto3.client.assert_called_once_with(
124-
"lambdainternal",
124+
"lambda",
125125
endpoint_url="http://localhost:3001",
126126
region_name="us-west-2",
127127
)

tests/runner_web_test.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ def test_should_handle_boto3_client_creation_with_custom_config():
417417

418418
# Assert - Verify boto3 client was called with correct parameters
419419
mock_boto3_client.assert_called_once_with(
420-
"lambdainternal",
420+
"lambda",
421421
endpoint_url="http://custom-endpoint:8080",
422422
region_name="eu-west-1",
423423
)
@@ -442,7 +442,7 @@ def test_should_handle_boto3_client_creation_with_defaults():
442442

443443
# Assert - Verify boto3 client was called with default parameters
444444
mock_boto3_client.assert_called_once_with(
445-
"lambdainternal",
445+
"lambda",
446446
endpoint_url="http://127.0.0.1:3001", # Default lambda_endpoint value
447447
region_name="us-west-2", # Default value
448448
)
@@ -467,30 +467,22 @@ def test_should_propagate_boto3_client_creation_exceptions():
467467
runner.start()
468468

469469

470-
def test_should_set_aws_data_path_during_start():
471-
"""Test that start() sets AWS_DATA_PATH environment variable through public API."""
470+
def test_should_create_boto3_client_during_start():
471+
"""Test that start() creates boto3 client correctly through public API."""
472472
# Arrange
473473
web_config = WebServiceConfig(host="localhost", port=5000)
474474
runner_config = WebRunnerConfig(web_service=web_config)
475475
runner = WebRunner(runner_config)
476476

477-
# Mock aws_durable_execution_sdk_python module path
478-
mock_package_path = "/mock/path/to/aws_durable_execution_sdk_python"
479-
expected_data_path = f"{mock_package_path}/botocore/data"
480-
481-
with (
482-
patch("os.path.dirname") as mock_dirname,
483-
patch("boto3.client") as mock_boto3_client,
484-
):
485-
mock_dirname.return_value = mock_package_path
477+
with patch("boto3.client") as mock_boto3_client:
486478
mock_client = Mock()
487479
mock_boto3_client.return_value = mock_client
488480

489481
# Act - Test public behavior
490482
runner.start()
491483

492-
# Assert - Verify environment variable was set
493-
assert os.environ["AWS_DATA_PATH"] == expected_data_path
484+
# Assert - Verify boto3 client was created
485+
mock_boto3_client.assert_called_once()
494486

495487
# Verify public behavior works
496488
runner.stop()
@@ -773,7 +765,7 @@ def test_should_pass_correct_boto3_client_to_lambda_invoker():
773765

774766
# Assert - Verify boto3 client was created with correct parameters
775767
mock_boto3_client.assert_called_once_with(
776-
"lambdainternal",
768+
"lambda",
777769
endpoint_url="http://test-endpoint:7777",
778770
region_name="ap-southeast-2",
779771
)

0 commit comments

Comments
 (0)