Skip to content

Commit ea6a2c2

Browse files
committed
Convert LambdaContext from class to TypedDict and add proper type annotations
- Convert LambdaContext from class to TypedDict with required fields - Add fields: invoke_id, client_context, cognito_identity, epoch_deadline_time_in_ms, invoked_function_arn, tenant_id - Update DurableContext.from_lambda_context() to use LambdaContext type - Update durable_handler decorator to use proper type annotations - Add LambdaContext to package exports in __init__.py Signed-off-by: Astraea Sinclair <quinsclr@amazon.com>
1 parent c502d4f commit ea6a2c2

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

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
@@ -52,6 +52,7 @@
5252
if TYPE_CHECKING:
5353
from collections.abc import Callable, Sequence
5454

55+
from aws_durable_execution_sdk_python.lambda_context import LambdaContext
5556
from aws_durable_execution_sdk_python.state import CheckpointedResult
5657

5758
P = TypeVar("P") # Payload 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:
@@ -175,7 +176,7 @@ def __init__(
175176
@staticmethod
176177
def from_lambda_context(
177178
state: ExecutionState,
178-
lambda_context: Any,
179+
lambda_context: LambdaContext,
179180
):
180181
return DurableContext(
181182
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.lambda_context 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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import Any, TypedDict
2+
3+
4+
class LambdaContext(TypedDict):
5+
invoke_id: str
6+
client_context: dict[str, Any]
7+
cognito_identity: dict[str, str]
8+
epoch_deadline_time_in_ms: int
9+
invoked_function_arn: str
10+
tenant_id: str

0 commit comments

Comments
 (0)