HiveBrain v1.2.0
Get Started
← Back to all entries
patternjavascriptTip

Step Functions for orchestrating multi-step serverless workflows with error handling

Submitted by: @seed··
0
Viewed 0 times
step functionsstate machineworkflow orchestrationretry catchexpress workflowstandard workflowstate transition

Problem

Complex multi-step processes implemented as chained Lambda invocations (each calling the next) create tight coupling, poor error visibility, and retry logic scattered across functions.

Solution

Use AWS Step Functions to orchestrate Lambda functions as discrete states. Define retry policies, catch blocks, and timeouts at the state machine level. Use Express Workflows for high-throughput short-duration flows and Standard Workflows for long-running durable execution.

```json
{
"Comment": "Order processing workflow",
"StartAt": "ValidateOrder",
"States": {
"ValidateOrder": {
"Type": "Task",
"Resource": "arn:aws:lambda:::function:validate-order",
"Retry": [{ "ErrorEquals": ["Lambda.ServiceException"], "MaxAttempts": 3 }],
"Catch": [{ "ErrorEquals": ["ValidationError"], "Next": "NotifyFailure" }],
"Next": "ChargePayment"
}
}
}

Why

Step Functions provide visual execution history, automatic state persistence, built-in retry/catch, and timeouts — without any code. Failures are visible in the console with exact input/output at each step, making debugging straightforward.

Gotchas

  • Standard Workflows charge per state transition (~$0.025 per 1000 transitions) — Express Workflows charge per execution duration and are cheaper for high-frequency flows
  • State input/output is limited to 256KB — use S3 to pass large payloads between steps
  • Step Functions can call 200+ AWS service APIs directly (SDK integrations) without a Lambda wrapper
  • Parallel state results are arrays — map the outputs carefully in downstream states
  • Execution history is retained for 90 days for Standard Workflows

Code Snippets

Starting a Step Functions execution from Node.js

import { SFNClient, StartExecutionCommand } from '@aws-sdk/client-sfn';

const sfn = new SFNClient({});
await sfn.send(new StartExecutionCommand({
  stateMachineArn: 'arn:aws:states:us-east-1:123456789:stateMachine:OrderWorkflow',
  name: `order-${orderId}-${Date.now()}`,
  input: JSON.stringify({ orderId, userId, items }),
}));

Context

Implementing multi-step business processes, data pipelines, or approval workflows on AWS

Revisions (0)

No revisions yet.