Skip to content

Commit 3bd9f27

Browse files
committed
Replace LambdaContext with a Protocol that matches source
Signed-off-by: Astraea Sinclair <quinsclr@amazon.com>
1 parent 00742dc commit 3bd9f27

File tree

5 files changed

+44
-6
lines changed

5 files changed

+44
-6
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
"""AWS Lambda Durable Executions Python SDK."""

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/lambda_context.py

Whitespace-only changes.

src/aws_durable_execution_sdk_python/types.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from abc import abstractmethod
66
from dataclasses import dataclass
7-
from typing import TYPE_CHECKING, Any, Generic, Protocol, TypeVar
7+
from typing import TYPE_CHECKING, Any, Generic, Protocol, TypeVar, runtime_checkable
88

99
if TYPE_CHECKING:
1010
from collections.abc import Callable, Mapping, Sequence
@@ -135,3 +135,39 @@ def create_callback(
135135
) -> Callback:
136136
"""Create a callback."""
137137
... # pragma: no cover
138+
139+
140+
class CognitoIdentity(Protocol): # pragma: no cover
141+
cognito_identity_id: str | None
142+
cognito_identity_pool_id: str | None
143+
144+
145+
class Client(Protocol): # pragma: no cover
146+
installation_id: str | None
147+
app_title: str | None
148+
app_version_name: str | None
149+
app_version_code: str | None
150+
app_package_name: str | None
151+
152+
153+
class ClientContext(Protocol): # pragma: no cover
154+
custom: str | None
155+
env: str | None
156+
client: Client | None
157+
158+
159+
@runtime_checkable
160+
class LambdaContext(Protocol): # pragma: no cover
161+
aws_request_id: str
162+
log_group_name: str | None
163+
log_stream_name: str | None
164+
function_name: str | None
165+
memory_limit_in_mb: str | None
166+
function_version: str | None
167+
invoked_function_arn: str | None
168+
tenant_id: str | None
169+
client_context: ClientContext | None
170+
identity: CognitoIdentity
171+
172+
def get_remaining_time_in_millis(self) -> int: ...
173+
def log(self, msg) -> None: ...

0 commit comments

Comments
 (0)