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
4 changes: 3 additions & 1 deletion src/aws_durable_execution_sdk_python_testing/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,9 @@ async def invoke() -> None:
self._store.save(execution)

response: DurableExecutionInvocationOutput = self._invoker.invoke(
execution.start_input.function_name, invocation_input
execution.start_input.function_name,
invocation_input,
execution.start_input.lambda_endpoint,
)

# Reload execution after invocation in case it was completed via checkpoint
Expand Down
25 changes: 16 additions & 9 deletions src/aws_durable_execution_sdk_python_testing/invoker.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from aws_durable_execution_sdk_python_testing.exceptions import (
DurableFunctionsTestError,
ServiceException,
)
from aws_durable_execution_sdk_python_testing.model import LambdaContext

Expand Down Expand Up @@ -63,6 +64,7 @@ def invoke(
self,
function_name: str,
input: DurableExecutionInvocationInput,
endpoint_url: str | None = None,
) -> DurableExecutionInvocationOutput: ... # pragma: no cover

def update_endpoint(
Expand Down Expand Up @@ -93,6 +95,7 @@ def invoke(
self,
function_name: str, # noqa: ARG002
input: DurableExecutionInvocationInput,
endpoint_url: str | None = None, # noqa: ARG002
) -> DurableExecutionInvocationOutput:
# TODO: reasses if function_name will be used in future
input_with_client = DurableExecutionInvocationInputWithClient.from_durable_execution_invocation_input(
Expand Down Expand Up @@ -140,19 +143,19 @@ def update_endpoint(self, endpoint_url: str, region_name: str) -> None:
self._current_endpoint = endpoint_url

def _get_client_for_execution(
self, durable_execution_arn: str, lambda_endpoint: str | None = None
self,
durable_execution_arn: str,
lambda_endpoint: str | None = None,
region_name: str | None = None,
) -> Any:
"""Get the appropriate client for this execution."""
# Use provided endpoint or fall back to cached endpoint for this execution
if lambda_endpoint:
# Client should already exist from update_endpoint() call
if lambda_endpoint not in self._endpoint_clients:
from aws_durable_execution_sdk_python_testing.exceptions import (
ServiceException,
)

raise ServiceException(
f"Lambda endpoint {lambda_endpoint} not configured. update_endpoint() must be called first."
self._endpoint_clients[lambda_endpoint] = boto3.client(
"lambdainternal",
endpoint_url=lambda_endpoint,
region_name=region_name or "us-east-1",
)
return self._endpoint_clients[lambda_endpoint]

Expand Down Expand Up @@ -188,12 +191,14 @@ def invoke(
self,
function_name: str,
input: DurableExecutionInvocationInput,
endpoint_url: str | None = None,
) -> DurableExecutionInvocationOutput:
"""Invoke AWS Lambda function and return durable execution result.

Args:
function_name: Name of the Lambda function to invoke
input: Durable execution invocation input
endpoint_url: Lambda endpoint url

Returns:
DurableExecutionInvocationOutput: Result of the function execution
Expand All @@ -214,7 +219,9 @@ def invoke(
raise InvalidParameterValueException(msg)

# Get the client for this execution
client = self._get_client_for_execution(input.durable_execution_arn)
client = self._get_client_for_execution(
input.durable_execution_arn, endpoint_url
)

try:
# Invoke AWS Lambda function using standard invoke method
Expand Down
4 changes: 3 additions & 1 deletion tests/executor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ def test_invoke_handler_success(
mock_invoker.create_invocation_input.assert_called_once_with(
execution=mock_execution
)
mock_invoker.invoke.assert_called_once_with("test-function", mock_invocation_input)
mock_invoker.invoke.assert_called_once_with(
"test-function", mock_invocation_input, None
)


def test_invoke_handler_execution_already_complete(
Expand Down
Loading