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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
//! DurableHandler trait definition and runner.
//!
//! Provide the [`DurableHandler`] trait and [`run`] entry point for trait-based
//! durable Lambda handlers (FR33). Internally wires up `lambda_runtime`, AWS config,
//! and `DurableContext` creation so users never interact with these directly.
use Arc;
use RealBackend;
use DurableContext;
use DurableError;
use parse_invocation;
use wrap_handler_result;
use ;
use crateTraitContext;
/// Trait for defining durable Lambda handlers with a structured, object-oriented approach.
///
/// Implement this trait on your struct to define handler logic. The [`handle`](DurableHandler::handle)
/// method receives the deserialized user event payload and a [`TraitContext`] with access
/// to all durable operations (step, wait, invoke, parallel, etc.).
///
/// Use [`run`] to wire up the Lambda runtime — you never interact with `lambda_runtime` directly.
///
/// # Examples
///
/// ```no_run
/// use durable_lambda_trait::prelude::*;
/// use async_trait::async_trait;
///
/// struct OrderProcessor;
///
/// #[async_trait]
/// impl DurableHandler for OrderProcessor {
/// async fn handle(
/// &self,
/// event: serde_json::Value,
/// mut ctx: TraitContext,
/// ) -> Result<serde_json::Value, DurableError> {
/// let result: Result<i32, String> = ctx.step("validate", || async {
/// Ok(42)
/// }).await?;
/// Ok(serde_json::json!({"result": result.unwrap()}))
/// }
/// }
///
/// #[tokio::main]
/// async fn main() -> Result<(), lambda_runtime::Error> {
/// durable_lambda_trait::run(OrderProcessor).await
/// }
/// ```
/// Run a durable Lambda handler using the trait-based approach.
///
/// This is the single entry point for trait-based durable Lambdas. It:
/// 1. Initializes AWS configuration and creates a Lambda client
/// 2. Creates a [`RealBackend`] for durable execution API calls
/// 3. Registers with `lambda_runtime` to receive invocations
/// 4. On each invocation, extracts durable execution metadata from the event,
/// creates a [`TraitContext`], and calls [`DurableHandler::handle`]
///
/// # Arguments
///
/// * `handler` — A struct implementing [`DurableHandler`]
///
/// # Errors
///
/// Returns `lambda_runtime::Error` if the Lambda runtime fails to start or
/// encounters a fatal error.
///
/// # Examples
///
/// ```no_run
/// use durable_lambda_trait::prelude::*;
/// use async_trait::async_trait;
///
/// struct MyHandler;
///
/// #[async_trait]
/// impl DurableHandler for MyHandler {
/// async fn handle(
/// &self,
/// event: serde_json::Value,
/// mut ctx: TraitContext,
/// ) -> Result<serde_json::Value, DurableError> {
/// let result: Result<i32, String> = ctx.step("process", || async {
/// Ok(42)
/// }).await?;
/// Ok(serde_json::json!({"done": true}))
/// }
/// }
///
/// #[tokio::main]
/// async fn main() -> Result<(), lambda_runtime::Error> {
/// durable_lambda_trait::run(MyHandler).await
/// }
/// ```
pub async