A durable workflow runs background work as named steps on AWS Lambda durable functions. AWS saves the result of each finished step, so after a crash, a deploy or a long wait, the run continues with the next step instead of starting over.
You write the steps with AWS's SDK, @aws/durable-execution-sdk-js (or aws-durable-execution-sdk-python). Stacktape deploys the workflow with your app, keeps runs in progress on their code across deploys, gives your app a typed way to start runs, alerts you when a run fails, and shows every run in the Stacktape Console.
Pricing: Lambda compute like a function, plus AWS's charge per step and wait (about $8 per million). Waiting costs nothing. See Pricing.
When to use
- Background jobs started from your API: reports, imports, emails, syncs. A step that already finished does not run again when a later step fails.
- Scheduled jobs with several steps, where a failure in step 4 should not repeat steps 1–3.
- Long workflows that wait hours or days: onboarding emails, trial reminders, approvals by a person.
When NOT to use
- Answering an HTTP request. A run starts in the background and cannot return a response. Put a Lambda function behind the API and start the run from it.
- One step longer than 30 minutes. Each invocation stops after
timeout(at most 1,800 seconds). Split the work into steps, or use a batch job. - Java, .NET, Go or containers. Durable workflows support Node.js and Python runtimes.
- A visual flow built from AWS service calls without code. Use a state machine. See state machine or durable workflow.
Basic example: a background job
An API endpoint starts a run that builds a report and emails it. connectTo gives the api function the workflow's address and the permissions to start runs.
The workflow is a function that takes the run's input and a context. Each context.step runs once, and AWS saves what it returns. Export the function, then export the handler that wraps it:
The API starts a run with start from @stacktape/workflows. The type parameter checks the input against the workflow function. The run ID makes the start safe to repeat: the same ID with the same input returns the existing run.
Install the packages in your project: npm install @aws/durable-execution-sdk-js @stacktape/workflows @aws-sdk/client-lambda. bundleAwsSdk: true bundles the Lambda client from your lockfile instead of using the one in the Lambda runtime, which can be older than the durable APIs.
Scheduled workflow
A schedule event starts a run on a cron or rate expression. If the sync of one customer fails, the run fails and alerts you, and the customers synced before it are not synced again when you run it again.
The loop is safe on replay: customerIds comes from a saved step, so every replay calls the same steps in the same order.
Long workflow: a wait and an approval
Onboarding sends a welcome email, waits a day, waits for a teammate to approve the account, and then sends tips. The run uses no compute while it waits.
The answer to a callback reaches the workflow as a string. serdes: defaultSerdes parses it as JSON, so approval is an object. Without it, parse the string yourself with JSON.parse.
Answer the callback from your app with approve or reject:
You can also approve from the CLI with workflow approve, or with the Approve button on the run in the Stacktape Console. The durable-workflow-onboarding starter is this workflow with an API, a local test and the ESLint rules.
Starting runs
| From | How |
|---|---|
| Your app code | start() from @stacktape/workflows, in a resource that has the workflow in connectTo |
| A schedule | A schedule event |
| Events | event-bus, sns, s3, cloudwatch-log and cloudwatch-alarm events |
| A queue or stream | sqs, kinesis-stream, dynamo-db-stream and kafka-topic events, only with runTimeout of 1,800 seconds or less |
| The CLI | stacktape workflow start |
| The Stacktape Console | Start run on the workflow's Runs tab |
AWS caps runs started from a queue or a stream at 30 minutes, so these events need runTimeout of 1,800 seconds or less. HTTP API, load balancer, AppSync, WebSocket and function URL events wait for a response, so a workflow cannot use them. Python apps start runs with boto3; see the guide.
Runs keep their code
Every deploy publishes a new version of the workflow and moves its stp-live alias to it. A run stays on the version that started it, including the environment variables of that deploy. A run that waits for a week wakes up with the code and configuration of the deploy that started it. Runs started after the deploy use the new code. Fast deploys work the same way.
So a code fix does not reach runs in progress. Stop them and run them again, or let them finish on the old code.
Stacktape does not delete old versions. AWS allows 300 GB of function code per region. If an account gets close, delete old versions that no run uses in the Lambda console.
Timeouts
timeoutlimits one invocation (default 300 seconds, at most 1,800). An invocation replays the finished steps and runs until the workflow waits or ends, so a step must finish within it.runTimeoutlimits the whole run, waits included (default and maximum 366 days). A run that exceeds it ends as timed out.historyRetentionDayskeeps the history of a finished run for 1–90 days (default 14). Until it ends, the run ID cannot be used for a new run.
You can change all three on a deployed workflow.
Alerts
Every workflow has two alarms without any configuration: one for failed runs and one for timed-out runs. They raise incidents in the Stacktape Console like other alarms. To get notified on a channel, define an alarm with the durable-workflow-failed-runs or durable-workflow-timed-out-runs trigger and add channels to it; it replaces the built-in one.
AWS doesn't emit the DurableExecutionFailed metric for every failed run. So once a minute, your stack also lists the workflow's runs that ended as failed or timed out, and counts them in the Stacktape/DurableWorkflows namespace under the minute they ended. Each alarm fires when either the AWS metric or this count sees a run. A run the check finds alerts about two minutes after it ended. A failure that both count is still one alarm and one notification.
A burst of failures sends one notification, with the number of failed runs, and one more when the workflow has had no failed run for five minutes. Set evaluationPeriods on your own alarm to change that window; it is at least 5, because a failed run is counted up to about three minutes after it ends. period stays 60 seconds.
Deleting a workflow
When a deploy deletes a workflow, or you delete the stack, its runs in progress cannot finish: each one fails the next time it continues, for example when its wait ends. A paused run can't be resumed either. Stacktape lists the running and paused runs first and asks for confirmation. It does the same before a deploy replaces the workflow's function, before stacktape dev updates a dev stage without the workflow, and before stacktape rollback returns to a release that did not have it. Without a terminal, or in agent mode, the command stops unless you pass --yes.
To end runs cleanly, stop them first with workflow stop or in the Console.
What data reaches Stacktape
Run inputs, outputs and step results stay in your AWS account. Stacktape doesn't store them.
- Reading runs. The Console's Runs tab reads runs, inputs, results, step results, errors and logs straight from your AWS account into your browser. They don't pass through Stacktape's servers. The CLI reads them with your AWS credentials.
- Changing runs from the Console. These actions go through the Stacktape API, which calls Lambda in your account. What passes through is sent on to Lambda and not stored or logged:
- Start: the input you enter.
- Run again and Rerun failed runs: the API reads each original run's input from Lambda and sends it back to Lambda.
- Approve: the callback ID and the result you enter.
- Reject: the callback ID and the reason you enter.
- Stop and Resume: only the run.
- Audit log. Each action records the AWS account, region, stage, workflow, run ID, the step name of an answered approval and the outcome. Never inputs, results or callback IDs.
Errors in a workflow's logs are tracked like errors of a Lambda function: when error tracking is on, the error message, stack frames and the matching log line go to Stacktape, with known shapes of sensitive text masked first. An error message can still contain values your code put into it, so don't put customer data in error messages. The run alarms send only the alarm, its metric and the number of runs, never run data. The minute check reads only the runs' status and times, in your account.
Limits
| Limit | Value |
|---|---|
Run length (runTimeout) | Up to 366 days |
One invocation (timeout) | Up to 30 minutes |
| Operations per run (steps, waits, callbacks, retries) | 30,000 |
| Size of one step result, callback answer or run input | 1 MB |
| Data written per run | 100 MB |
History kept after a run ends (historyRetentionDays) | 1–90 days |
| Run ID | 1–64 letters, digits, - or _ |
| Runs started by queue and stream events | 30 minutes |
| Runtimes | nodejs24.x, nodejs22.x, python3.14, python3.13 |
| Regions | Every region Stacktape supports except me-south-1 (Bahrain) |
Pricing
AWS charges for durable workflows on top of Lambda compute. In us-east-1:
- $8 per million operations. A step, a wait, a callback and each retry of a step count as one operation each.
- $0.25 per GB of data written (step results and inputs) and $0.15 per GB-month of history kept.
- Lambda compute for each invocation, including the replay of finished steps after a wait. Replays are short, because finished steps return their saved result.
Waiting costs no compute. A run with four steps and a three-day wait uses about 5 operations and a few seconds of compute, so 100,000 such runs cost about $4 in operations. Stacktape adds no fee per run.
Each workflow also has a fixed monitoring cost, even when no run starts. In us-east-1, about $0.70 a month:
- The two run alarms watch two metrics each: $0.40 a month ($0.10 per metric in an alarm). The first 10 alarm metrics in an account are free.
- The check of failed runs, once a minute in your stack's service function (2,048 MB, about 0.2 seconds when few runs failed): 43,200 invocations, about $0.30 a month. The Lambda free tier covers it in most accounts.
- In hours with failed or timed-out runs, the check writes a custom metric: about $0.0004 per hour for each of the two ($0.30 per metric-month, billed by the hour).
The price estimate shows this in its note, because the price catalog has no CloudWatch alarm prices.
Durable Workflow FAQ
Does a step run exactly once?
No. A step that finished is not run again, but a step can run more than once if it fails, or if its invocation crashes after the work and before AWS saves the result. Make outside writes safe to repeat, for example with an idempotency key. See writing safe steps.
Can I start a run from code that is not deployed with Stacktape?
Yes. Set STP_<NAME>_ARN (for onboarding: STP_ONBOARDING_ARN) to the workflow's alias ARN, or pass the ARN to start() instead of the name. The caller needs lambda:InvokeFunction on the alias ARN and lambda:GetDurableExecution on the function's runs (<function ARN>:*). The referenceable parameter arn is the alias ARN.
How do I see what a run is doing?
Open the workflow's Runs tab in the Stacktape Console, or run stacktape workflow show. Both list each step with its attempts, errors, input and output.
API Reference
DurableWorkflowProps