Skip to main content

durable_execution

Attribute Macro durable_execution 

Source
#[durable_execution]
Expand description

Attribute macro that transforms an async function into a durable Lambda handler.

This macro wraps your async function to integrate with AWS Lambda’s durable execution service. It handles:

  • Parsing DurableExecutionInvocationInput from the Lambda event
  • Creating ExecutionState and DurableContext for the handler
  • Processing results, errors, and suspend signals
  • Returning DurableExecutionInvocationOutput with appropriate status

§Function Signature

The decorated function must have the following signature:

async fn handler_name(event: EventType, ctx: DurableContext) -> Result<ResultType, DurableError>

Where:

  • EventType must implement serde::Deserialize
  • ResultType must implement serde::Serialize

§Example

use durable_execution_sdk::{durable_execution, DurableContext, DurableError};
use serde::{Deserialize, Serialize};

#[derive(Deserialize)]
struct MyEvent {
    order_id: String,
}

#[derive(Serialize)]
struct MyResult {
    status: String,
}

#[durable_execution]
async fn my_handler(event: MyEvent, ctx: DurableContext) -> Result<MyResult, DurableError> {
    // Your workflow logic here
    let result = ctx.step(|_| Ok("processed".to_string()), None).await?;
    Ok(MyResult { status: result })
}

§Generated Code

The macro generates two functions:

  1. An inner async function (__<name>_inner) containing the user’s original logic
  2. A Lambda handler wrapper that accepts LambdaEvent<DurableExecutionInvocationInput> and delegates to run_durable_handler with the inner function

All runtime concerns (event deserialization, state management, context creation, result/error/suspend handling) are encapsulated in run_durable_handler.