Skip to content

Commit 98ec6c2

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
1 parent c502d4f commit 98ec6c2

4 files changed

Lines changed: 16 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
@@ -20,6 +20,7 @@
2020
ValidationError,
2121
)
2222
from aws_durable_execution_sdk_python.identifier import OperationIdentifier
23+
from aws_durable_execution_sdk_python.lambda_context import LambdaContext
2324
from aws_durable_execution_sdk_python.lambda_service import OperationSubType
2425
from aws_durable_execution_sdk_python.logger import Logger, LogInfo
2526
from aws_durable_execution_sdk_python.operation.callback import (
@@ -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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
FatalError,
1414
SuspendExecution,
1515
)
16+
from aws_durable_execution_sdk_python.lambda_context import LambdaContext
1617
from aws_durable_execution_sdk_python.lambda_service import (
1718
DurableServiceClient,
1819
ErrorObject,
@@ -187,10 +188,10 @@ def create_succeeded(cls, result: str) -> DurableExecutionInvocationOutput:
187188

188189
def durable_handler(
189190
func: Callable[[Any, DurableContext], Any],
190-
) -> Callable[[Any, Any], Any]:
191+
) -> Callable[[Any, LambdaContext], Any]:
191192
logger.debug("Starting durable execution handler...")
192193

193-
def wrapper(event: Any, context: Any) -> MutableMapping[str, Any]:
194+
def wrapper(event: Any, context: LambdaContext) -> MutableMapping[str, Any]:
194195
invocation_input: DurableExecutionInvocationInput
195196
service_client: DurableServiceClient
196197

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)