Skip to content

Commit ba93922

Browse files
committed
docs: invoke
- Rewrites invoke.md to be equally useful to TypeScript, Python, and Java developers - Removes Table of Contents, back-links, Terminology, Key Features, Best Practices, FAQ, and Testing sections - Adds invoke walkthrough example for all three languages - Documents method signatures, InvokeConfig, naming, configuration, and error handling per language - Adds sequence diagram showing both checkpoints (start and result) and the suspend/resume lifecycle - Adds note distinguishing context.invoke() from the Lambda Invoke API - Adds new example files under examples/{typescript,python,java}/ operations/invoke/ closes #36, closes #72, closes #54
1 parent 2f01895 commit ba93922

13 files changed

Lines changed: 396 additions & 545 deletions

File tree

docs/sdk-reference/operations/invoke.md

Lines changed: 158 additions & 545 deletions
Large diffs are not rendered by default.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import software.amazon.lambda.durable.DurableContext;
2+
import software.amazon.lambda.durable.DurableHandler;
3+
import software.amazon.lambda.durable.exception.InvokeFailedException;
4+
import software.amazon.lambda.durable.exception.InvokeTimedOutException;
5+
6+
public class HandleInvocationError extends DurableHandler<OrderEvent, OrderResult> {
7+
8+
@Override
9+
public OrderResult handle(OrderEvent event, DurableContext context) {
10+
try {
11+
PaymentResult payment = context.invoke(
12+
"process-payment",
13+
"payment-processor-function:live",
14+
event,
15+
PaymentResult.class
16+
);
17+
return OrderResult.success(payment.getTransactionId());
18+
} catch (InvokeTimedOutException e) {
19+
return OrderResult.failed("payment timed out");
20+
} catch (InvokeFailedException e) {
21+
return OrderResult.failed(e.getMessage());
22+
}
23+
}
24+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// sync
2+
<T, U> T invoke(String name, String functionName, U payload, Class<T> resultType)
3+
<T, U> T invoke(String name, String functionName, U payload, Class<T> resultType, InvokeConfig config)
4+
<T, U> T invoke(String name, String functionName, U payload, TypeToken<T> resultType)
5+
<T, U> T invoke(String name, String functionName, U payload, TypeToken<T> resultType, InvokeConfig config)
6+
7+
// async
8+
<T, U> DurableFuture<T> invokeAsync(String name, String functionName, U payload, Class<T> resultType)
9+
<T, U> DurableFuture<T> invokeAsync(String name, String functionName, U payload, Class<T> resultType, InvokeConfig config)
10+
<T, U> DurableFuture<T> invokeAsync(String name, String functionName, U payload, TypeToken<T> resultType)
11+
<T, U> DurableFuture<T> invokeAsync(String name, String functionName, U payload, TypeToken<T> resultType, InvokeConfig config)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import software.amazon.lambda.durable.DurableContext;
2+
import software.amazon.lambda.durable.DurableHandler;
3+
import software.amazon.lambda.durable.config.InvokeConfig;
4+
5+
public class InvokeWithConfig extends DurableHandler<OrderEvent, OrderResult> {
6+
7+
@Override
8+
public OrderResult handle(OrderEvent event, DurableContext context) {
9+
InvokeConfig config = InvokeConfig.builder()
10+
.tenantId(event.getTenantId())
11+
.build();
12+
13+
return context.invoke(
14+
"process-order",
15+
"order-processor-function:live",
16+
event,
17+
OrderResult.class,
18+
config
19+
);
20+
}
21+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import software.amazon.lambda.durable.DurableContext;
2+
import software.amazon.lambda.durable.DurableHandler;
3+
4+
public class ProcessOrder extends DurableHandler<OrderEvent, OrderResult> {
5+
6+
@Override
7+
public OrderResult handle(OrderEvent event, DurableContext context) {
8+
ValidationResult validation = context.invoke(
9+
"validate-order",
10+
"validate-order-function:live",
11+
event,
12+
ValidationResult.class
13+
);
14+
15+
if (!validation.isValid()) {
16+
return OrderResult.rejected(validation.getReason());
17+
}
18+
19+
PaymentResult payment = context.invoke(
20+
"process-payment",
21+
"payment-processor-function:live",
22+
event,
23+
PaymentResult.class
24+
);
25+
26+
return OrderResult.completed(payment.getTransactionId());
27+
}
28+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from aws_durable_execution_sdk_python import DurableContext, durable_execution
2+
from aws_durable_execution_sdk_python.exceptions import CallableRuntimeError
3+
4+
5+
@durable_execution
6+
def handler(event: dict, context: DurableContext) -> dict:
7+
try:
8+
result = context.invoke(
9+
"payment-processor-function:live",
10+
{"order_id": event["order_id"]},
11+
name="process-payment",
12+
)
13+
return {"status": "success", "result": result}
14+
except CallableRuntimeError as e:
15+
return {"status": "failed", "reason": str(e)}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def invoke(
2+
function_name: str,
3+
payload: P,
4+
name: str | None = None,
5+
config: InvokeConfig[P, R] | None = None,
6+
) -> R: ...
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from aws_durable_execution_sdk_python import DurableContext, durable_execution
2+
from aws_durable_execution_sdk_python.config import InvokeConfig
3+
4+
5+
@durable_execution
6+
def handler(event: dict, context: DurableContext) -> dict:
7+
config = InvokeConfig(tenant_id=event.get("tenant_id"))
8+
9+
result = context.invoke(
10+
"order-processor-function:live",
11+
{"order_id": event["order_id"]},
12+
name="process-order",
13+
config=config,
14+
)
15+
16+
return result
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from aws_durable_execution_sdk_python import DurableContext, durable_execution
2+
3+
4+
@durable_execution
5+
def handler(event: dict, context: DurableContext) -> dict:
6+
validation = context.invoke(
7+
"validate-order-function:live",
8+
{"order_id": event["order_id"], "amount": event["amount"]},
9+
name="validate-order",
10+
)
11+
12+
if not validation["valid"]:
13+
return {"status": "rejected", "reason": validation.get("reason")}
14+
15+
payment = context.invoke(
16+
"payment-processor-function:live",
17+
{"order_id": event["order_id"], "amount": event["amount"]},
18+
name="process-payment",
19+
)
20+
21+
return {"status": "completed", "transaction_id": payment["transaction_id"]}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import {
2+
DurableContext,
3+
InvokeError,
4+
durableExecution,
5+
} from "aws-durable-execution-sdk-js";
6+
7+
export const handler = durableExecution(
8+
async (event: { orderId: string }, context: DurableContext) => {
9+
try {
10+
const result = await context.invoke(
11+
"process-payment",
12+
"payment-processor-function:live",
13+
{ orderId: event.orderId },
14+
);
15+
return { status: "success", result };
16+
} catch (err) {
17+
if (err instanceof InvokeError) {
18+
return { status: "failed", reason: err.message };
19+
}
20+
throw err;
21+
}
22+
},
23+
);

0 commit comments

Comments
 (0)