durable-lambda-macro
Proc-macro for zero-boilerplate AWS Lambda durable execution handler registration.
Overview
durable-lambda-macro is a proc-macro crate that provides the #[durable_execution] attribute macro. It eliminates all Lambda runtime boilerplate by generating a main() function that wires up AWS configuration, the Lambda client, the durable execution backend, and the Lambda runtime event loop.
This is one of four API styles for the durable-rust SDK. All styles produce identical runtime behavior -- they differ only in ergonomics:
| Crate | Style | Best for |
|---|---|---|
durable-lambda-closure |
Closure-native (recommended) | Simplest syntax, no traits or macros |
durable-lambda-macro |
Proc-macro | Zero boilerplate with #[durable_execution] |
durable-lambda-trait |
Trait-based | OOP pattern, shared state via struct fields |
durable-lambda-builder |
Builder-pattern | Most configurable, tracing/error hooks |
Choose the macro style when you want the absolute minimum boilerplate -- just annotate your handler function and the macro does the rest.
Features
#[durable_execution]attribute macro that transforms an async function into a complete Lambda binary- Zero boilerplate -- no
#[tokio::main], noservice_fn, no AWS config setup - Compile-time validation of handler signature: second parameter must be
DurableContext, return type must beResult<_, DurableError> - Generates
main()with Lambda runtime, AWS client,RealBackend, and event parsing - Full access to all 8 durable operations via the generated
DurableContext
Getting Started
Add both durable-lambda-macro and durable-lambda-core to your Cargo.toml:
[]
= "0.1"
= "0.1"
= "1"
Note: durable-lambda-core is needed for DurableContext and DurableError types. The tokio and lambda_runtime dependencies are handled by the generated code.
Usage
Basic Handler
Annotate an async function with #[durable_execution]:
use durable_execution;
use DurableContext;
use DurableError;
async
// main() is generated by the macro -- do not define it yourself
Handler with All Operations
use durable_execution;
use DurableContext;
use DurableError;
use StepOptions;
async
What the Macro Generates
The #[durable_execution] attribute preserves your handler function and generates a #[tokio::main] async fn main() that:
- Loads AWS configuration with default credentials
- Creates an
aws_sdk_lambda::Client - Wraps the client in a
RealBackendfor durable execution API calls - Registers with
lambda_runtimeviaservice_fnto receive invocations - On each invocation: parses durable execution metadata from the event, creates a
DurableContext, and calls your handler
Conceptually, the generated code looks like:
// Your handler function is preserved as-is
async
// This is generated by the macro:
async
Compile-Time Validations
The macro validates your handler signature at compile time:
- The function must be
async - The second parameter must be
DurableContext - The return type must be
Result<serde_json::Value, DurableError>
If any validation fails, you get a clear compile error pointing to the issue.
Testing
Because the macro generates main(), you cannot directly call the handler in tests. Instead, extract your business logic into a separate function that takes DurableContext and test it with durable-lambda-testing:
// In your handler module:
pub async
// In tests:
use *;
async
API Reference
| Item | Description |
|---|---|
#[durable_execution] |
Attribute macro for handler functions |
DurableContext |
Main context type (from durable-lambda-core) |
DurableError |
SDK error type (from durable-lambda-core) |
StepOptions |
Step configuration (from durable-lambda-core) |
Full API documentation: docs.rs/durable-lambda-macro
License
Licensed under either of MIT or Apache-2.0 at your option.