AWS Lambda
Run the same config as one Lambda durable function behind a Function URL, on Postgres, with what each request costs, the quotas, the IAM role and the deployment notes checked against a real function.
This page is for a team deploying the engine on AWS. At the end you will have one Lambda durable function behind a Function URL that serves the API and runs every journey as a durable execution, with its data in your Postgres and email through SES. The config, workflows and templates are the same ones the Cloudflare and Node hosts run; only the entry file and the infrastructure differ. The notes below were checked against a real durable Lambda (Node 24, us-east-1).
Install
@aws/durable-execution-sdk-js and @aws-sdk/client-lambda are optional peer dependencies, needed only by sendwend/aws. The durable SDK's own type declarations reference aws-lambda, so a TypeScript project that type-checks dependencies (no skipLibCheck) also needs @types/aws-lambda.
The handler
env is your parsed process.env. A minimal schema:
sesEmailTransport with no credentials reads AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN at send time, which is the execution role's temporary credentials on Lambda.
| Option | Default | Meaning |
|---|---|---|
env | Required | The validated environment |
store | Required | The Postgres store; AWS needs its execution registry, so use postgresJsStore |
email | None | The transport; without one the email channel fails its sends |
executionTimeoutMs | None | The function's ExecutionTimeout. A workflow that could outlive it fails at startup |
startRetryMs | 12 hours | How long an unconfirmed start is retried. Keep it under the execution retention |
stopDrainMs | 15 minutes | How long an erasure waits after stopping an execution. At least the function's Timeout |
lambda | @aws-sdk/client-lambda client | The Lambda control plane, with the execution role |
authorize | The API_TOKEN bearer | Your own check; see Authentication |
observer, messages, runtime and contractMode work as on the other hosts.
One handler, three inputs
The handler tells three inputs apart by the event's top-level shape, so no HTTP body can pass for the others:
- A Function URL request. The HTTP API, as on Cloudflare. A journey it starts is its own durable execution, submitted with an asynchronous
Invokeof this function's numbered version under a stable execution name, and the request returns. Reads (GET,HEAD) are answered outside a durable step, so their bodies are not checkpointed; a write runs in one step that is not retried, because the caller is waiting and retries the request itself. - A run (
$workflow.run). One journey instance. Steps, delays and waits map onto the durable SDK'sstep,waitand callbacks; a wait parks on a fresh callback, recorded in Postgres, which the next relevant event completes. A run executes only if its input matches, byte for byte, a start the host recorded, so nothing else that can invoke the function can start a workflow for a user. - A sweep (
{ "type": "$workflow.sweep" }). The segment sweep, plus retrying starts whose submit was never confirmed and reconciling executions the platform ended (timeout, stop) into the ledger. Send it from EventBridge Scheduler, or callPOST /segments/sweepfrom an existing cron. Without one, clock-only segments, date triggers and this upkeep do not happen. Each page of the sweep is a durable step, so an invocation cut short by the timeout is re-invoked and replays the pages already done.
Starts are never doubled
A start is recorded with its entry in one transaction (the execution table), so a lost Invoke response is retried with the same name and payload and never re-entered as a second execution. Retries stop after startRetryMs (12 hours) and the start is left unresolved. A failed entry that is entered again gets a new execution, never the closed one.
Erasure waits for running invocations
POST /users/forget commits the tombstone, stops the user's admitted executions, then waits stopDrainMs before erasing, because a stop does not interrupt an invocation already running; it goes on to its next checkpoint. Until then the erasure answers erased: false and the sweep finishes it. The tombstone takes the user's lock, which every write about the user also takes, so nothing of theirs lands after it and no second pass is needed.
Deploy: one artifact per version
Publish a numbered version and point the live alias, which the Function URL is bound to, at it. Each version carries its compiled bundle and makes it live by itself, only over an older one. Each route records the version that applied it, and an instance it starts runs on that version, so its IR and its code always match, even while an older version is still serving. Executions stay on the version that started them. POST /deploy of an arbitrary bundle is always refused.
An AWS SAM resource:
Before publishing, run pnpm exec sendwend plan --database-url $DATABASE_URL in CI. On AWS the platform pins each execution to its function version, so a template change cannot reach a running journey; the segment and action checks still matter, since those come from the database. Create the tables first (Postgres).
Versions
- Publish numbered versions behind the
livealias.$LATESTlets a paused execution resume on changed code. - Do not delete a version while executions are pinned to it.
- Rolling the alias back does not roll the routes back: the newer bundle stays live until
POST /bundle/deployfrom the restored version.
The Function URL
Use AuthType: NONE and protect the API in the app. Not every caller can sign a request:
| Caller | Routes |
|---|---|
| Your backend | /ingest, /devices, /users/forget, ... |
| Recipients' mail clients and browsers | /t/o, /t/l, /t/u |
| Gmail and Yahoo one-click unsubscribe | POST /t/u/<message> (RFC 8058) |
| iOS notification extension, service worker | POST /t/d, POST /t/p |
An alias has one URL and one auth type, and the tracking and one-click routes must stay public:
AWS_IAMwould break those routes. SigV4 also takes theAuthorizationheader, so the bearer could not travel with it.- CloudFront's origin access control does not help either: with it, every POST must carry the body's SHA-256 in
x-amz-content-sha256, and a mail provider's one-click POST does not.
Keep the routes public and protect the API with the API_TOKEN bearer or your own authorize. Production refuses to serve without one of the two.
Resource policy. Grant lambda:InvokeFunctionUrl to everyone (FunctionUrlAuthType: NONE) and lambda:InvokeFunction only with lambda:InvokedViaFunctionUrl = true, so the URL cannot be used to invoke the function directly.
CloudFront and WAF in front, without OAC. A custom domain needs CloudFront or another HTTPS proxy anyway; Route 53 alone cannot terminate TLS for a Function URL. Add a rate-based WAF rule there: every request that reaches the function starts a durable execution and is billed, even one the app answers 401. Reserved concurrency caps what a flood can cost.
What a request costs
Every Function URL request is a durable execution of its own:
| Execution | Durable ops | Per million |
|---|---|---|
GET (pixel, redirect, /health), no step | 1 | about $9 |
POST (an event, an identify), one step | 2 | about $17 |
| A plain, non-durable Lambda for comparison | - | about $1 |
| A journey: email, delay, one wake-up, email | 24 | about $190 |
Durable operations cost $8 per million, on top of Lambda's request and duration charges. That is negligible at thousands of requests a month and worth a second, non-durable function for HTTP at tens of millions. Server-side latency stays small: /health takes about 6 ms, a write 40 to 300 ms. These figures are the SDK README's, measured when it was written; check AWS's current pricing before you budget on them.
Quotas
- Starting durable executions: 3,000 per second (6,000 in us-east-1, us-west-2 and eu-west-1). HTTP requests and journey starts share it.
- 30,000 operations per execution, which cannot be raised. A wait attempt costs about five: the callback plus four steps.
- 1 MB per operation's payload. Reads are answered outside a step so their bodies are not checkpointed. On the engine's side an event payload is at most 128 KiB as JSON.
Timeouts and retention
- Set
DurableConfig.ExecutionTimeoutto the longest journey (waits, delays and the goal window), up to 366 days, and pass the same value asjourneyLambda({ executionTimeoutMs }): a workflow that could outlive it fails at startup instead of being stopped midway. RetentionPeriodInDays(1 to 90) only keeps history after an execution ends. KeepstartRetryMs(12 hours) well under it.- Keep
stopDrainMs(15 minutes) at least the function'sTimeout: a stop does not interrupt a running invocation.
Execution role
AWSLambdaBasicDurableExecutionRolePolicy(checkpoints, state, logs).- On
arn:...:function:<name>andarn:...:function:<name>:*:lambda:InvokeFunction,lambda:SendDurableExecutionCallbackSuccess,lambda:GetDurableExecution,lambda:StopDurableExecutionandlambda:ListDurableExecutionsByFunction. Durable execution ARNs carry the version, so an unqualified ARN alone matches nothing. ses:SendEmailwhen sending through SES.
Email through SES
The one-click unsubscribe header needs an https WORKFLOW_ORIGIN; over http no List-Unsubscribe is sent. Mailbox providers honor the header only when DKIM signs it, so check one real message for dkim=pass with list-unsubscribe in h=. sesEmailTransport also takes configurationSetName for event publishing or a dedicated IP pool.
Memory and push
Size memory for the app; the store is remote. APNs goes over the package's own Node HTTP/2 client, because Node 24's fetch speaks HTTP/1.1 only. Opens and clicks are classified as on the other hosts, except that the requesting network is known on Cloudflare only, so the rules that use it do not apply here and the human click rate reads higher.
Pitfalls
- No sweep, no upkeep. Without the EventBridge schedule, unconfirmed starts are not retried, executions the platform ended stay
runningin the ledger, and clock-driven journeys never start. $LATESTin production. A paused execution can resume on changed code. Always invoke through the numberedlivealias.- An ExecutionTimeout shorter than a journey. The platform stops it midway and the entry is recorded as failed. Pass
executionTimeoutMsso the mismatch fails the deploy's first invocation instead. - One database schema per function. As on every host, two engines on one schema swap each other's routes.