Skip to main content

DurableHandler

Trait DurableHandler 

Source
pub trait DurableHandler:
    Send
    + Sync
    + 'static {
    // Required method
    fn handle<'life0, 'async_trait>(
        &'life0 self,
        event: Value,
        ctx: TraitContext,
    ) -> Pin<Box<dyn Future<Output = Result<Value, DurableError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
}
Expand description

Trait for defining durable Lambda handlers with a structured, object-oriented approach.

Implement this trait on your struct to define handler logic. The 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

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
}

Required Methods§

Source

fn handle<'life0, 'async_trait>( &'life0 self, event: Value, ctx: TraitContext, ) -> Pin<Box<dyn Future<Output = Result<Value, DurableError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handle a durable Lambda invocation.

§Arguments
  • event — The deserialized user event payload
  • ctx — A TraitContext providing access to all durable operations
§Errors

Return DurableError on failure. The runtime converts this to a Lambda error response.

Implementors§