Skip to content

Commit cc11a42

Browse files
FullyTypedAstraea Quinn S
authored andcommitted
Replace LambdaContext with a Protocol that matches source
Signed-off-by: Astraea Sinclair <[email protected]>
1 parent 00742dc commit cc11a42

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

src/aws_durable_execution_sdk_python/context.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
from collections.abc import Callable, Sequence
5454

5555
from aws_durable_execution_sdk_python.state import CheckpointedResult
56+
from aws_durable_execution_sdk_python.types import LambdaContext
5657

5758
P = TypeVar("P") # Payload type
5859
R = TypeVar("R") # Result type
@@ -149,7 +150,7 @@ class DurableContext(DurableContextProtocol):
149150
def __init__(
150151
self,
151152
state: ExecutionState,
152-
lambda_context: Any | None = None,
153+
lambda_context: LambdaContext | None = None,
153154
parent_id: str | None = None,
154155
logger: Logger | None = None,
155156
) -> None:
@@ -171,7 +172,7 @@ def __init__(
171172
@staticmethod
172173
def from_lambda_context(
173174
state: ExecutionState,
174-
lambda_context: Any,
175+
lambda_context: LambdaContext,
175176
):
176177
return DurableContext(
177178
state=state,

src/aws_durable_execution_sdk_python/execution.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
if TYPE_CHECKING:
2626
from collections.abc import Callable, MutableMapping
2727

28+
from aws_durable_execution_sdk_python.types import LambdaContext
29+
2830

2931
logger = logging.getLogger(__name__)
3032

@@ -187,10 +189,10 @@ def create_succeeded(cls, result: str) -> DurableExecutionInvocationOutput:
187189

188190
def durable_handler(
189191
func: Callable[[Any, DurableContext], Any],
190-
) -> Callable[[Any, Any], Any]:
192+
) -> Callable[[Any, LambdaContext], Any]:
191193
logger.debug("Starting durable execution handler...")
192194

193-
def wrapper(event: Any, context: Any) -> MutableMapping[str, Any]:
195+
def wrapper(event: Any, context: LambdaContext) -> MutableMapping[str, Any]:
194196
invocation_input: DurableExecutionInvocationInput
195197
service_client: DurableServiceClient
196198

src/aws_durable_execution_sdk_python/types.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,19 @@ def create_callback(
135135
) -> Callback:
136136
"""Create a callback."""
137137
... # pragma: no cover
138+
139+
140+
class LambdaContext(Protocol): # pragma: no cover
141+
aws_request_id: str
142+
log_group_name: str | None = None
143+
log_stream_name: str | None = None
144+
function_name: str | None = None
145+
memory_limit_in_mb: str | None = None
146+
function_version: str | None = None
147+
invoked_function_arn: str | None = None
148+
tenant_id: str | None = None
149+
client_context: Any | None = None
150+
identity: Any | None = None
151+
152+
def get_remaining_time_in_millis(self) -> int: ...
153+
def log(self, msg) -> None: ...

0 commit comments

Comments
 (0)