-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathparallel_with_invoke.py
More file actions
39 lines (33 loc) · 1.31 KB
/
parallel_with_invoke.py
File metadata and controls
39 lines (33 loc) · 1.31 KB
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
31
32
33
34
35
36
37
38
39
"""Example demonstrating parallel operations that invoke child functions."""
from typing import Any
from aws_durable_execution_sdk_python.config import ParallelConfig
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[str]:
"""Execute parallel branches where each invokes a different child function."""
return context.parallel(
functions=[
lambda ctx: ctx.invoke(
function_name="greeter",
payload={"name": "Alice"},
name="greet_alice",
),
lambda ctx: ctx.invoke(
function_name="greeter",
payload={"name": "Bob"},
name="greet_bob",
),
lambda ctx: ctx.invoke(
function_name="greeter",
payload={"name": "Charlie"},
name="greet_charlie",
),
],
name="parallel_with_invoke",
config=ParallelConfig(max_concurrency=3),
).get_results()
def greeter_handler(event: dict, context: Any) -> dict:
"""Child handler that creates a greeting."""
name = event.get("name", "World")
return {"greeting": f"Hello, {name}!"}