durable-lambda-trait
Trait-based API style for AWS Lambda durable execution workflows.
Overview
durable-lambda-trait provides a trait-based API for the durable-rust SDK. Implement the DurableHandler trait on your struct, and use durable_lambda_trait::run(MyHandler) to start the Lambda runtime.
This style is ideal for complex handlers that benefit from an object-oriented pattern -- shared configuration, database clients, or other state can live as struct fields, naturally accessible inside handle() via &self.
API Style Comparison
All four API styles produce identical runtime behavior. They differ only in ergonomics:
| Crate | Style | Boilerplate | Configuration | Best for |
|---|---|---|---|---|
durable-lambda-closure |
Closure-native (recommended) | Minimal | None | Getting started, most use cases |
durable-lambda-macro |
Proc-macro | Lowest | None | Zero-boilerplate preference |
durable-lambda-trait |
Trait-based | Moderate | Via struct fields | Complex handlers with shared state |
durable-lambda-builder |
Builder-pattern | Moderate | .with_tracing(), .with_error_handler() |
Production deployments needing hooks |
Choose durable-lambda-trait when your handler needs shared state (config, clients, caches) or when you prefer a familiar OOP pattern.
Features
DurableHandlertrait withasync fn handle(&self, event, ctx)methodTraitContextwrappingDurableContextwith all 8 durable operationsdurable_lambda_trait::run(handler)single entry point handling all runtime wiringpreludemodule re-exporting all types for single-line imports- Struct fields as shared state -- configuration, clients, and caches accessible via
&self - Full access to all durable operations: Step, Wait, Callback, Invoke, Parallel, Map, Child Context, Logging
Getting Started
Add to your Cargo.toml:
[]
= "0.1"
= "0.1"
= { = "1", = ["full"] }
= "1"
Note: async-trait is required because Rust does not yet support async methods in traits natively (as of this crate version).
Usage
Basic Handler
use *;
use async_trait;
;
async
Handler with Shared State
The trait-based approach shines when your handler needs access to shared configuration or clients:
use *;
use async_trait;
async
All Operations
The TraitContext exposes the same 8 operations as every other API style:
use *;
use async_trait;
;
Prelude
Import everything you need with a single line:
use *;
This re-exports TraitContext, DurableHandler, DurableContext, DurableError, StepOptions, ExecutionMode, and all other commonly used types.
Testing
Test your handler implementation with durable-lambda-testing -- no AWS credentials needed:
use *;
async
API Reference
| Type | Description |
|---|---|
DurableHandler |
Trait to implement on your handler struct |
TraitContext |
Wrapper context with all 8 durable operations |
run(handler) |
Entry point that wires up Lambda runtime and AWS backend |
Re-exported from durable-lambda-core:
| Type | Description |
|---|---|
DurableContext |
Core context type (used in parallel/map/child_context callbacks) |
DurableError |
SDK infrastructure error type |
StepOptions |
Step configuration (retries, backoff, timeout, retry_if) |
ExecutionMode |
Replaying or Executing |
Full API documentation: docs.rs/durable-lambda-trait
License
Licensed under either of MIT or Apache-2.0 at your option.