-
Notifications
You must be signed in to change notification settings - Fork 481
Expand file tree
/
Copy pathusing_logger.py
More file actions
24 lines (16 loc) · 805 Bytes
/
Copy pathusing_logger.py
File metadata and controls
24 lines (16 loc) · 805 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from aws_durable_execution_sdk_python import DurableContext, durable_execution # type: ignore[import-not-found]
from aws_lambda_powertools import Logger
logger = Logger(service="order-processing")
@durable_execution
def handler(event: dict, context: DurableContext) -> str:
# Set Logger on the context for automatic deduplication
context.set_logger(logger)
# Logs via context.logger appear only once, even during replays
context.logger.info("Starting workflow", extra={"order_id": event.get("order_id")})
result: str = context.step(
lambda _: "processed",
name="process_order",
)
# This log won't repeat when the function replays after completing the step above
context.logger.info("Workflow completed", extra={"result": result})
return result