blog.rust.gay

Lambda's durable functions get a Rust SDK

AWS announced general availability of the open-source Lambda Durable Execution SDK for Rust on November 19. The SDK lets a Rust developer write a long-running workflow as an ordinary async function, with durable operations that checkpoint their progress and can pause for up to a year while waiting on an external event.

That is a different promise from ordinary serverless. A normal Lambda invocation is short-lived and stateless; if it fails, the retry starts from the beginning. A durable function keeps a record of what has completed, so a retry can resume instead of replaying every side effect. The interesting question is not whether that is useful. It is where the state machine now lives, and what that costs.

What durable execution changes

Every workflow engine is a state machine with a persistence layer. Step Functions makes that explicit: you define states, transitions and waits, and the service stores the execution history. Temporal and similar systems put the state machine in a worker and replay deterministic code to rebuild it.

Lambda durable functions take the second approach and move it into the Lambda runtime. The function is the orchestration. Each durable operation records a checkpoint, and when the function is interrupted, the runtime replays the function until it reaches the point where it stopped. Operations that already completed return their saved results instead of running again.

That is the core bargain. You get long waits, retries, and human approvals without running a separate workflow service. You also get a new class of bug: code that is not safe to replay. A step that sends an email, charges a card, or writes a row must be wrapped in a durable operation, or a retry will do it twice. The runtime can checkpoint only what you tell it to checkpoint.

The programming model

The SDK's model is deliberately close to ordinary Rust. A durable function is an async function. Durable operations are awaited like any other future, and independent operations can run concurrently. That matters for latency: a workflow that calls three services in parallel should not serialize them just because it is durable.

The building blocks are steps, callbacks, child-function invocations, and timed waits. A step runs work and saves its result. A callback pauses the workflow until an external system completes it, which is the primitive behind human-in-the-loop and agent-in-the-loop approval. A child invocation calls another durable function. A timed wait sleeps for a duration without holding a runtime slot.

The callback is the most interesting piece for AI pipelines. A model call can complete quickly, but a review by a person can take hours or days. Without a durable callback, the usual pattern is a database row, a queue, and a separate worker to resume the workflow. With a callback, the pause is part of the function's own control flow.

The catch is that the workflow's state is now split between your code and the runtime's checkpoint store. You need to think about what is safe to re-execute, how to version a workflow that changes while executions are paused, and how to observe a function that may be dormant for a year.

The Rust toolchain

The developer experience is the part AWS is selling hardest, and it is concrete. Add the aws-durable-execution-sdk crate with cargo add, build with Cargo Lambda, and deploy a single binary on the provided.al2023 runtime. There is no sidecar and no separate workflow definition file.

For testing, the SDK includes a LocalRunner. It lets a developer run complete workflows under cargo test without network access or AWS credentials. That is a meaningful improvement over testing against a deployed state machine, because most workflow bugs are control-flow bugs: a missing await, a step that runs twice, a branch that never resumes.

A single binary also simplifies the deployment story. The function and its workflow logic ship together, so there is no version skew between a workflow definition and the code that implements it. The trade-off is that changing the workflow means deploying a new function version, and paused executions may still be running the old code. Durable systems need a migration story for in-flight executions, and the SDK does not make that disappear.

The trade-offs

The first trade-off is determinism. Replay works only if the code takes the same path on the second run. A workflow that branches on the current time, a random value, or an external API response that is not checkpointed will diverge. The durable operations are the safe points. Everything between them must be deterministic or idempotent.

The second is state ownership. The checkpoint store belongs to the Lambda runtime, which is convenient until you need to query it, export it, or move the workflow to another system. A separate workflow engine gives you an API for that state. A function-local model gives you the function's logs and whatever the SDK exposes.

The third is vendor coupling. A durable function is not portable to another compute platform in the way a plain async function is. The code is Rust, but the semantics are Lambda's. That is acceptable if Lambda is already the deployment target, and a real cost if the workflow might move.

The fourth is observability. A paused execution is not a running process. The usual metrics, traces and logs still exist, but the question "what is this workflow waiting for?" needs an answer from the checkpoint layer. Teams should decide how they will answer it before they have a thousand paused executions.

The replay test

The most important test for a durable function is not the happy path. It is the interruption. Run the workflow, kill it between two steps, and assert that the second run does not repeat the first step's side effect. The LocalRunner makes that test possible without deploying anything.

A useful pattern is to inject a failure after every durable operation, one at a time, and check the resulting state. That forces you to mark each side effect as a step and to think about what happens when the process dies between the checkpoint and the next line of code. The runtime can only recover to a checkpoint, so anything outside a step is replayable code.

Determinism is the other half. A workflow that calls SystemTime::now(), generates a random ID, or branches on an uncached API response will take a different path on replay. The fix is not to ban those inputs; it is to capture them in a step and reuse the saved result. The same discipline applies to feature flags, environment variables and anything else that can change between the first run and the retry.

Idempotency is not free, either. A durable step can be retried, so the downstream system must tolerate the same request twice. An idempotency key derived from the workflow and step identifiers is usually enough, but it has to be part of the design, not an afterthought. The SDK gives you checkpoints; it does not give you exactly-once delivery to an external service.

The last test is versioning. Change the workflow while an execution is paused, and the resumed run may take a branch the original code never had. Keep the old version deployable until the paused executions drain, or design the workflow so that new steps are additive. This is the same problem workflow engines have had for years, and moving the state machine into the function does not make it disappear.

When it fits

The best fit is a workflow that is mostly orchestration with a few side effects: an infrastructure rollout that waits for approval, a deployment that pauses between stages, a data pipeline that calls a model and then waits for a human to review the output. These are cases where the state machine is simple, the waits are long, and the value of keeping everything in one function is high.

A separate workflow engine is still the better choice when the workflow is large, when many teams need to inspect and modify it, or when the execution history must be queried as a first-class dataset. Durable functions move the state machine into the function; that is an advantage for small workflows and a constraint for big ones.

There is also a testing argument for the SDK. LocalRunner plus cargo test makes the replay path testable in CI. A workflow engine with a local emulator can do the same, but the Rust SDK's version is close enough to ordinary unit testing that teams are more likely to write the tests. That matters more than the feature list.

The cost model is the remaining question. A durable function that waits for a year is not free, even if it is not consuming a runtime slot. The checkpoint store, the invocations that resume it, and the observability around it all have a price. For a workflow that waits minutes, plain Lambda plus a queue may be cheaper and simpler. For one that waits days and needs an audit trail, the durable primitive is worth the overhead. Measure both before committing.

The team-size factor matters too. A small team that already deploys Rust to Lambda gets a single artifact and one mental model. A platform team that already runs a workflow engine gets centralized visibility and reuse. Neither choice is wrong; they optimize for different kinds of scale.

Conclusion

The Lambda Durable Execution SDK for Rust is a solid addition to the serverless toolkit. It brings checkpoints, callbacks and long waits into the function, and it does so with the Rust toolchain developers already use: Cargo, Cargo Lambda, provided.al2023, and cargo test.

The thing to watch is not the API. It is the operational model. Durable functions make state explicit, which is good, and they make replay a first-class concern, which is new for most Lambda teams. Start with a workflow that has one long wait and one side effect, test the replay path locally, and measure how long a paused execution takes to resume. That will tell you more than the launch post.

Sources


← back to posts