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
22 changes: 4 additions & 18 deletions src/aws_durable_execution_sdk_python/lambda_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,9 @@ def load_preview_botocore_models() -> None:
@staticmethod
def initialize_local_runner_client() -> LambdaClient:
endpoint = os.getenv(
"LOCAL_RUNNER_ENDPOINT", "http://host.docker.internal:5000"
"DURABLE_LOCAL_RUNNER_ENDPOINT", "http://host.docker.internal:5000"
)
region = os.getenv("LOCAL_RUNNER_REGION", "us-west-2")
region = os.getenv("DURABLE_LOCAL_RUNNER_REGION", "us-west-2")

# The local runner client needs execute-api as the signing service name,
# so we have a second `lambdainternal-local` boto model with this.
Expand All @@ -860,29 +860,15 @@ def initialize_local_runner_client() -> LambdaClient:
return LambdaClient(client=client)

@staticmethod
def initialize_from_endpoint_and_region(endpoint: str, region: str) -> LambdaClient:
def initialize_from_env() -> LambdaClient:
LambdaClient.load_preview_botocore_models()
client = boto3.client(
"lambdainternal",
endpoint_url=endpoint,
region_name=region,
)

logger.debug(
"Initialized lambda client with endpoint: '%s', region: '%s'",
endpoint,
region,
)
logger.debug("Initialized lambda client")
return LambdaClient(client=client)

@staticmethod
def initialize_from_env() -> LambdaClient:
return LambdaClient.initialize_from_endpoint_and_region(
# it'll prob end up being https://lambda.us-east-1.amazonaws.com or similar
endpoint=os.getenv("DEX_ENDPOINT", "http://host.docker.internal:5000"),
region=os.getenv("DEX_REGION", "us-east-1"),
)

def checkpoint(
self,
durable_execution_arn: str,
Expand Down
12 changes: 0 additions & 12 deletions tests/e2e/execution_int_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
from aws_durable_execution_sdk_python.lambda_service import (
CheckpointOutput,
CheckpointUpdatedExecutionState,
LambdaClient,
OperationAction,
OperationType,
)
Expand Down Expand Up @@ -392,14 +391,3 @@ def mock_checkpoint(
assert checkpoint.action is OperationAction.START
assert checkpoint.operation_id == "1"
assert checkpoint.wait_options.seconds == 1


def test_lambda_client_initialization():
"""Test initialization of real Lambda client with specified endpoint and region."""
endpoint = "https://durable.durable-functions.devo.us-west-2.lambda.aws.a2z.com"
region = "us-west-2"

client = LambdaClient.initialize_from_endpoint_and_region(endpoint, region)

assert client is not None
assert client.client is not None
49 changes: 6 additions & 43 deletions tests/lambda_service_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -771,25 +771,12 @@ def test_state_output_from_dict_empty_operations():
assert output.next_marker == "marker123"


@patch("aws_durable_execution_sdk_python.lambda_service.boto3")
def test_lambda_client_initialize_from_endpoint_and_region(mock_boto3):
"""Test LambdaClient.initialize_from_endpoint_and_region method."""
mock_client = Mock()
mock_boto3.client.return_value = mock_client

lambda_client = LambdaClient.initialize_from_endpoint_and_region(
"https://test.com", "us-east-1"
)

mock_boto3.client.assert_called_once_with(
"lambdainternal", endpoint_url="https://test.com", region_name="us-east-1"
)
assert lambda_client.client == mock_client


@patch.dict(
"os.environ",
{"LOCAL_RUNNER_ENDPOINT": "http://test:5000", "LOCAL_RUNNER_REGION": "us-west-1"},
{
"DURABLE_LOCAL_RUNNER_ENDPOINT": "http://test:5000",
"DURABLE_LOCAL_RUNNER_REGION": "us-west-1",
},
)
@patch("aws_durable_execution_sdk_python.lambda_service.boto3")
def test_lambda_client_initialize_local_runner_client(mock_boto3):
Expand All @@ -805,20 +792,6 @@ def test_lambda_client_initialize_local_runner_client(mock_boto3):
assert lambda_client.client == mock_client


@patch.dict(
"os.environ", {"DEX_ENDPOINT": "https://lambda.test.com", "DEX_REGION": "eu-west-1"}
)
@patch(
"aws_durable_execution_sdk_python.lambda_service.LambdaClient.initialize_from_endpoint_and_region"
)
def test_lambda_client_initialize_from_env(mock_init):
"""Test LambdaClient.initialize_from_env method."""
LambdaClient.initialize_from_env()
mock_init.assert_called_once_with(
endpoint="https://lambda.test.com", region="eu-west-1"
)


def test_lambda_client_checkpoint():
"""Test LambdaClient.checkpoint method."""
mock_client = Mock()
Expand Down Expand Up @@ -1005,14 +978,6 @@ def test_lambda_client_stop():
assert result == "2023-01-01T00:00:00Z"


@pytest.mark.skip(reason="little informal integration test for interactive running.")
def test_lambda_client_with_env_defaults():
client = LambdaClient.initialize_from_endpoint_and_region(
"http://127.0.0.1:5000", "us-east-1"
)
client.get_execution_state("9692ca80-399d-4f52-8d0a-41acc9cd0492", next_marker="")


def test_durable_service_client_protocol_checkpoint():
"""Test DurableServiceClient protocol checkpoint method signature."""
mock_client = Mock(spec=DurableServiceClient)
Expand Down Expand Up @@ -1526,11 +1491,9 @@ def test_lambda_client_initialize_local_runner_client_defaults(mock_boto3):

@patch.dict("os.environ", {}, clear=True)
@patch(
"aws_durable_execution_sdk_python.lambda_service.LambdaClient.initialize_from_endpoint_and_region"
"aws_durable_execution_sdk_python.lambda_service.LambdaClient.initialize_from_env"
)
def test_lambda_client_initialize_from_env_defaults(mock_init):
"""Test LambdaClient.initialize_from_env with default environment values."""
LambdaClient.initialize_from_env()
mock_init.assert_called_once_with(
endpoint="http://host.docker.internal:5000", region="us-east-1"
)
mock_init.assert_called_once_with()