β οΈ EXPERIMENTAL & BETA: This package is in active development and should be used with caution in production.
AWS World implementation for Workflow DevKit - Run durable, resumable workflows on AWS Lambda with DynamoDB, SQS, and S3.
Workflow DevKit brings durability, reliability, and observability to async JavaScript. Build workflows and AI Agents that can suspend, resume, and maintain state with ease - all with simple TypeScript functions.
aws-workflow is a World implementation that runs your workflows on AWS infrastructure, providing:
- β Serverless execution on AWS Lambda
- β State persistence with DynamoDB
- β Message queuing with SQS
- β Large payload storage with S3
- β Automatic retries and error handling
- β No vendor lock-in - same code runs locally or on any cloud
- Install
npm install aws-workflow-
Write workflows in your project (e.g.,
workflows/) -
Bootstrap AWS resources
npx aws-workflow bootstrap -y- Deploy your workflow to Lambda
npx aws-workflow deploy- Node.js 18+
- AWS CLI configured with credentials
- A Next.js 14+ application
npm install aws-workflow workflowThis creates the required AWS infrastructure (DynamoDB tables, SQS queues, S3 bucket, Lambda function):
npx aws-workflow bootstrap -yWhat this does:
- Creates 5 DynamoDB tables (workflow runs, steps, events, hooks, stream chunks)
- Creates 2 SQS queues (workflow queue, step queue)
- Creates 1 S3 bucket for large payload storage
- Deploys Lambda worker function
- Outputs environment variables to
.env.aws
Cost estimate: Free tier eligible. Typical cost: $5-20/month for moderate usage.
Copy the generated environment variables from .env.aws to your Next.js .env.local:
# From bootstrap output
WORKFLOW_QUEUE_URL=https://sqs.us-east-1.amazonaws.com/...
WORKFLOW_STEP_QUEUE_URL=https://sqs.us-east-1.amazonaws.com/...
WORKFLOW_RUNS_TABLE=workflow_runs
WORKFLOW_STEPS_TABLE=workflow_steps
WORKFLOW_EVENTS_TABLE=workflow_events
WORKFLOW_HOOKS_TABLE=workflow_hooks
WORKFLOW_STREAM_CHUNKS_TABLE=workflow_stream_chunks
WORKFLOW_STREAM_BUCKET=workflow-streams-...
# Add your AWS credentials
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your-access-key
AWS_SECRET_ACCESS_KEY=your-secret-keyAdd to your next.config.ts:
import { withWorkflow } from 'workflow/next';
export default withWorkflow({
experimental: {
serverActions: {
bodySizeLimit: '10mb',
},
},
});Create workflows/user-signup.ts:
import { sleep } from 'workflow';
export async function handleUserSignup(email: string) {
'use workflow';
// Step 1: Create user
const user = await createUser(email);
// Step 2: Send welcome email
await sendWelcomeEmail(email);
// Step 3: Wait 7 days (workflow suspends - no resources consumed!)
await sleep('7 days');
// Step 4: Send follow-up
await sendFollowUpEmail(email);
return { userId: user.id, status: 'completed' };
}
async function createUser(email: string) {
'use step';
// Your user creation logic
return { id: '123', email };
}
async function sendWelcomeEmail(email: string) {
'use step';
// Send email via Resend, SendGrid, etc.
}
async function sendFollowUpEmail(email: string) {
'use step';
// Send follow-up email
}Whenever you add or update workflows, deploy them:
npx aws-workflow deployWhat this does:
- Compiles your TypeScript workflows
- Builds Next.js to generate workflow bundles
- Packages Lambda handler with your workflows
- Deploys to AWS Lambda (no Docker required!)
From your Next.js API route or Server Action:
import { handleUserSignup } from '@/workflows/user-signup';
export async function POST(request: Request) {
const { email } = await request.json();
// Start the workflow
const handle = await handleUserSignup(email);
return Response.json({
workflowId: handle.id,
status: 'started'
});
}That's it! Your workflow is now running on AWS Lambda. π
βββββββββββββββββββ
β Next.js App β
β (Your Code) β
ββββββββββ¬βββββββββ
β
β Triggers workflow
βΌ
βββββββββββββββββββ ββββββββββββββββ
β SQS Queues βββββββΆβ Lambda Workerβ
β (Orchestration) β β (Executes) β
βββββββββββββββββββ ββββββββ¬ββββββββ
β
βββββββββββββ΄ββββββββββββ
β β
ββββββββββββΌβββββββββ βββββββββββΌβββββββββ
β DynamoDB β β S3 Bucket β
β (State & Runs) β β (Large Payloads) β
βββββββββββββββββββββ ββββββββββββββββββββ
Steps automatically retry on failure with exponential backoff.
Workflow state is persisted to DynamoDB - resume from any point.
Use sleep() to pause workflows for minutes, hours, or days without consuming resources.
Query workflow status, inspect step execution, view history:
import { getWorkflowRun } from 'aws-workflow';
const run = await getWorkflowRun(workflowId);
console.log(run.status); // 'running' | 'completed' | 'failed'Run multiple steps concurrently:
export async function processOrder(orderId: string) {
'use workflow';
const [payment, inventory, shipping] = await Promise.all([
processPayment(orderId),
reserveInventory(orderId),
calculateShipping(orderId),
]);
return { payment, inventory, shipping };
}# Bootstrap AWS infrastructure (first time only)
npx aws-workflow bootstrap -y
# Deploy workflows to Lambda
npx aws-workflow deploy
# View Lambda logs in real-time
npx aws-workflow logs
# Tear down all AWS resources
npx aws-workflow teardown
# Get current AWS resource info
npx aws-workflow outputs| Variable | Description | Required |
|---|---|---|
WORKFLOW_QUEUE_URL |
SQS queue URL for workflow orchestration | β |
WORKFLOW_STEP_QUEUE_URL |
SQS queue URL for step execution | β |
WORKFLOW_RUNS_TABLE |
DynamoDB table for workflow runs | β |
WORKFLOW_STEPS_TABLE |
DynamoDB table for step execution | β |
WORKFLOW_STREAM_BUCKET |
S3 bucket for large payloads | β |
AWS_REGION |
AWS region | β |
AWS_ACCESS_KEY_ID |
AWS access key (local dev) | β * |
AWS_SECRET_ACCESS_KEY |
AWS secret key (local dev) | β * |
*Not required when running on AWS (uses IAM roles)
- Lambda executions are short-lived (typically <500ms per step)
- DynamoDB uses on-demand pricing (no upfront cost)
- SQS has free tier of 1M requests/month
- S3 is only used for payloads >256KB
Typical monthly cost for moderate usage: $5-20
# Clean and rebuild
rm -rf cdk.out .next node_modules/.cache
npm run deploy# Check Lambda logs
npx aws-workflow logs
# Verify environment variables
npx aws-workflow outputsEnsure your Next.js app uses npm (not pnpm) for flat node_modules structure:
rm -rf node_modules pnpm-lock.yaml
npm installCheck out the example Next.js app for a complete implementation including:
- User signup workflow with email sequence
- Multi-step ordering process
- Error handling and retries
- Webhook integrations
Contributions are welcome!
MIT - see LICENSE.md
Built with β€οΈ by Langtrace