pub async fn run<F, Fut>(handler: F) -> Result<(), Error>where
F: Fn(Value, ClosureContext) -> Fut + Send + Sync + 'static,
Fut: Future<Output = Result<Value, DurableError>> + Send,Expand description
Run a durable Lambda handler using the closure-native approach.
This is the single entry point for closure-native durable Lambdas. It:
- Initializes AWS configuration and creates a Lambda client
- Creates a
RealBackendfor durable execution API calls - Registers with
lambda_runtimeto receive invocations - On each invocation, extracts durable execution metadata from the event,
creates a
ClosureContext, and calls the user handler
The handler function receives the deserialized user event payload and an
owned ClosureContext (take it as mut to call operations), and returns
a JSON result or a DurableError.
§Arguments
handler— An async function taking the user event and aClosureContext, returningResult<serde_json::Value, DurableError>
§Errors
Returns lambda_runtime::Error if the Lambda runtime fails to start or
encounters a fatal error.
§Examples
use durable_lambda_closure::prelude::*;
async fn handler(
event: serde_json::Value,
mut ctx: ClosureContext,
) -> 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_closure::run(handler).await
}