Skip to main content

run

Function run 

Source
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:

  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

§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
}