Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7,864 changes: 0 additions & 7,864 deletions .github/model/lambda.json

This file was deleted.

4 changes: 0 additions & 4 deletions .github/workflows/deploy-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,6 @@ jobs:
role-session-name: pythonTestingLibraryGitHubIntegrationTest
aws-region: ${{ env.AWS_REGION }}

- name: Install custom Lambda model
run: |
aws configure add-model --service-model file://.github/model/lambda.json --service-name lambda

- name: Install Hatch
run: pip install hatch

Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
]
dependencies = [
"boto3>=1.40.30",
"boto3>=1.42.1",
"requests>=2.25.0",
"aws_durable_execution_sdk_python>=1.0.0",
]
Expand Down Expand Up @@ -59,7 +59,7 @@ dependencies = [
"pytest",
"pytest-cov",
"ruff",
"aws_durable_execution_sdk_python @ {env:AWS_DURABLE_SDK_URL:git+ssh://[email protected]/aws/aws-durable-execution-sdk-python.git}",
"aws_durable_execution_sdk_python>=1.0.0",
]

[tool.hatch.envs.test.scripts]
Expand All @@ -72,7 +72,7 @@ cov = "pytest --cov-report=term-missing --cov-config=pyproject.toml --cov=src/aw
dependencies = [
"boto3",
"PyYAML",
"aws_durable_execution_sdk_python @ {env:AWS_DURABLE_SDK_URL:git+ssh://[email protected]/aws/aws-durable-execution-sdk-python.git}",
"aws_durable_execution_sdk_python>=1.0.0",
]
[tool.hatch.envs.examples.scripts]
cli = "python examples/cli.py {args}"
Expand Down
9 changes: 2 additions & 7 deletions src/aws_durable_execution_sdk_python_testing/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def get_durable_execution_history_command(self, args: argparse.Namespace) -> int
def _create_boto3_client(
self, endpoint_url: str | None = None, region_name: str | None = None
) -> Any:
"""Create boto3 client for lambdainternal service.
"""Create boto3 client for Lambda service.

Args:
endpoint_url: Optional endpoint URL override
Expand All @@ -471,18 +471,13 @@ def _create_boto3_client(
Exception: If client creation fails
"""
try:
# Set up AWS data path for boto models
package_path = os.path.dirname(aws_durable_execution_sdk_python.__file__)
data_path = f"{package_path}/botocore/data"
os.environ["AWS_DATA_PATH"] = data_path

# Use provided values or fall back to config
final_endpoint = endpoint_url or self.config.local_runner_endpoint
final_region = region_name or self.config.local_runner_region

# Create client with local endpoint - no AWS access keys required
return boto3.client(
"lambdainternal",
"lambda",
endpoint_url=final_endpoint,
region_name=final_region,
)
Expand Down
8 changes: 3 additions & 5 deletions src/aws_durable_execution_sdk_python_testing/invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,7 @@ def __init__(self, lambda_client: Any) -> None:
def create(endpoint_url: str, region_name: str) -> LambdaInvoker:
"""Create with the boto lambda client."""
invoker = LambdaInvoker(
boto3.client(
"lambdainternal", endpoint_url=endpoint_url, region_name=region_name
)
boto3.client("lambda", endpoint_url=endpoint_url, region_name=region_name)
)
invoker._current_endpoint = endpoint_url
invoker._endpoint_clients[endpoint_url] = invoker.lambda_client
Expand All @@ -150,7 +148,7 @@ def update_endpoint(self, endpoint_url: str, region_name: str) -> None:
with self._lock:
if endpoint_url not in self._endpoint_clients:
self._endpoint_clients[endpoint_url] = boto3.client(
"lambdainternal", endpoint_url=endpoint_url, region_name=region_name
"lambda", endpoint_url=endpoint_url, region_name=region_name
)
self.lambda_client = self._endpoint_clients[endpoint_url]
self._current_endpoint = endpoint_url
Expand All @@ -166,7 +164,7 @@ def _get_client_for_execution(
if lambda_endpoint:
if lambda_endpoint not in self._endpoint_clients:
self._endpoint_clients[lambda_endpoint] = boto3.client(
"lambdainternal",
"lambda",
endpoint_url=lambda_endpoint,
region_name=region_name or "us-east-1",
)
Expand Down
31 changes: 7 additions & 24 deletions src/aws_durable_execution_sdk_python_testing/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,10 +698,7 @@ def wait_for_callback(

# Timeout reached
elapsed = time.time() - start_time
msg = (
f"Callback did not available within {timeout}s "
f"(elapsed: {elapsed:.1f}s."
)
msg = f"Callback did not available within {timeout}s (elapsed: {elapsed:.1f}s."
raise TimeoutError(msg)


Expand Down Expand Up @@ -850,26 +847,20 @@ def stop(self) -> None:
self._executor = None

def _create_boto3_client(self) -> Any:
"""Create boto3 client for lambdainternal service.
"""Create boto3 client for Lambda service.

Configures AWS data path and creates a boto3 client with the
local runner endpoint and region from configuration.
Creates a boto3 client with the local runner endpoint and region from configuration.

Returns:
Configured boto3 client for lambdainternal service
Configured boto3 client for Lambda service

Raises:
Exception: If client creation fails - exceptions propagate naturally
for CLI to handle as general Exception
"""
# Set up AWS data path for boto models
package_path = os.path.dirname(aws_durable_execution_sdk_python.__file__)
data_path = f"{package_path}/botocore/data"
os.environ["AWS_DATA_PATH"] = data_path

# Create client with Lambda endpoint configuration
return boto3.client(
"lambdainternal",
"lambda",
endpoint_url=self._config.lambda_endpoint,
region_name=self._config.local_runner_region,
)
Expand Down Expand Up @@ -904,14 +895,9 @@ def __init__(
self.lambda_endpoint = lambda_endpoint
self.poll_interval = poll_interval

# Set up AWS data path for custom boto models (durable execution fields)
package_path = os.path.dirname(aws_durable_execution_sdk_python.__file__)
data_path = f"{package_path}/botocore/data"
os.environ["AWS_DATA_PATH"] = data_path

client_config = boto3.session.Config(parameter_validation=False)
self.lambda_client = boto3.client(
"lambdainternal",
"lambda",
endpoint_url=lambda_endpoint,
region_name=region,
config=client_config,
Expand Down Expand Up @@ -1154,10 +1140,7 @@ def wait_for_callback(

# Timeout reached
elapsed = time.time() - start_time
msg = (
f"Callback did not available within {timeout}s "
f"(elapsed: {elapsed:.1f}s."
)
msg = f"Callback did not available within {timeout}s (elapsed: {elapsed:.1f}s."
raise TimeoutError(msg)

def _fetch_execution_history(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,10 @@ def create(cls, operation_name: str) -> AwsRestJsonSerializer:
InvalidParameterValueException: If serializer creation fails
"""
try:
package_path = os.path.dirname(aws_durable_execution_sdk_python.__file__)
data_path = f"{package_path}/botocore/data"

# Load service model
os.environ["AWS_DATA_PATH"] = data_path
loader = botocore.loaders.Loader()
loader.search_paths.append(data_path)

raw_model = loader.load_service_model("lambdainternal", "service-2")
raw_model = loader.load_service_model("lambda", "service-2")
service_model = ServiceModel(raw_model)

# Create serializer (rest-json protocol)
Expand Down Expand Up @@ -190,15 +185,10 @@ def create(cls, operation_name: str) -> AwsRestJsonDeserializer:
InvalidParameterValueException: If deserializer creation fails
"""
try:
package_path = os.path.dirname(aws_durable_execution_sdk_python.__file__)
data_path = f"{package_path}/botocore/data"

# Load service model
os.environ["AWS_DATA_PATH"] = data_path
loader = botocore.loaders.Loader()
loader.search_paths.append(data_path)

raw_model = loader.load_service_model("lambdainternal", "service-2")
raw_model = loader.load_service_model("lambda", "service-2")
service_model = ServiceModel(raw_model)

# Create parser (rest-json protocol)
Expand Down
28 changes: 9 additions & 19 deletions tests/cli_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -985,29 +985,19 @@ def test_get_durable_execution_history_command_handles_connection_error() -> Non
assert exit_code == 1


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

with patch("boto3.client") as mock_boto3_client:
with patch("os.environ") as mock_environ:
with patch("os.path.dirname") as mock_dirname:
mock_dirname.return_value = "/path/to/aws_durable_execution_sdk_python"
app._create_boto3_client() # noqa: SLF001

app._create_boto3_client() # noqa: SLF001

# Verify AWS_DATA_PATH is set
mock_environ.__setitem__.assert_called_with(
"AWS_DATA_PATH",
"/path/to/aws_durable_execution_sdk_python/botocore/data",
)

# Verify boto3 client is created with correct parameters
mock_boto3_client.assert_called_once_with(
"lambdainternal",
endpoint_url=app.config.local_runner_endpoint,
region_name=app.config.local_runner_region,
)
# Verify boto3 client is created with correct parameters
mock_boto3_client.assert_called_once_with(
"lambda",
endpoint_url=app.config.local_runner_endpoint,
region_name=app.config.local_runner_region,
)


def test_create_boto3_client_handles_creation_failure() -> None:
Expand Down
2 changes: 1 addition & 1 deletion tests/invoker_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def test_lambda_invoker_create():
assert isinstance(invoker, LambdaInvoker)
assert invoker.lambda_client is mock_client
mock_boto3.client.assert_called_once_with(
"lambdainternal",
"lambda",
endpoint_url="http://localhost:3001",
region_name="us-west-2",
)
Expand Down
24 changes: 8 additions & 16 deletions tests/runner_web_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def test_should_handle_boto3_client_creation_with_custom_config():

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

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


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

# Mock aws_durable_execution_sdk_python module path
mock_package_path = "/mock/path/to/aws_durable_execution_sdk_python"
expected_data_path = f"{mock_package_path}/botocore/data"

with (
patch("os.path.dirname") as mock_dirname,
patch("boto3.client") as mock_boto3_client,
):
mock_dirname.return_value = mock_package_path
with patch("boto3.client") as mock_boto3_client:
mock_client = Mock()
mock_boto3_client.return_value = mock_client

# Act - Test public behavior
runner.start()

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

# Verify public behavior works
runner.stop()
Expand Down Expand Up @@ -773,7 +765,7 @@ def test_should_pass_correct_boto3_client_to_lambda_invoker():

# Assert - Verify boto3 client was created with correct parameters
mock_boto3_client.assert_called_once_with(
"lambdainternal",
"lambda",
endpoint_url="http://test-endpoint:7777",
region_name="ap-southeast-2",
)
Expand Down
8 changes: 2 additions & 6 deletions tests/web/serialization_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ def test_aws_rest_json_serializer_should_create_serializer_with_boto_components(
assert serialized_data == b'{"test": "value"}'

# Verify boto setup calls
mock_loader.load_service_model.assert_called_once_with(
"lambdainternal", "service-2"
)
mock_loader.load_service_model.assert_called_once_with("lambda", "service-2")
mock_service_model_class.assert_called_once_with(mock_raw_model)
mock_create_serializer.assert_called_once_with("rest-json", include_validation=True)
mock_service_model.operation_model.assert_called_once_with(operation_name)
Expand Down Expand Up @@ -270,9 +268,7 @@ def test_aws_rest_json_deserializer_should_create_deserializer_with_boto_compone
assert deserialized_data == {"test": "value"}

# Verify boto setup calls
mock_loader.load_service_model.assert_called_once_with(
"lambdainternal", "service-2"
)
mock_loader.load_service_model.assert_called_once_with("lambda", "service-2")
mock_service_model_class.assert_called_once_with(mock_raw_model)
mock_create_parser.assert_called_once_with("rest-json")
mock_service_model.operation_model.assert_called_once_with(operation_name)
Expand Down
Loading