-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmap_with_invoke.py
More file actions
30 lines (23 loc) · 991 Bytes
/
map_with_invoke.py
File metadata and controls
30 lines (23 loc) · 991 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
25
26
27
28
29
30
"""Example demonstrating map operations that invoke child functions."""
from typing import Any
from aws_durable_execution_sdk_python.config import MapConfig
from aws_durable_execution_sdk_python.context import DurableContext
from aws_durable_execution_sdk_python.execution import durable_execution
@durable_execution
def handler(_event: Any, context: DurableContext) -> list[int]:
"""Process items using map where each item invokes a child function."""
items = [1, 2, 3, 4, 5]
return context.map(
inputs=items,
func=lambda ctx, item, index, _: ctx.invoke(
function_name="doubler",
payload={"value": item},
name=f"invoke_item_{index}",
),
name="map_with_invoke",
config=MapConfig(max_concurrency=2),
).get_results()
def doubler_handler(event: dict, context: Any) -> dict:
"""Child handler that doubles the input value."""
value = event.get("value", 0)
return {"result": value * 2}