pub async fn run<H: DurableHandler>(handler: H) -> Result<(), Error>Expand description
Run a durable Lambda handler using the trait-based approach.
This is the single entry point for trait-based 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
TraitContext, and callsDurableHandler::handle
§Arguments
handler— A struct implementingDurableHandler
§Errors
Returns lambda_runtime::Error if the Lambda runtime fails to start or
encounters a fatal error.
§Examples
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
}