Retry & Catch: Declarative Error Handling

~8 min read

How Step Functions moves error-handling logic out of application code and into the workflow definition itself.

A Retry field on a Task state lists one or more error types to catch, along with an interval, a maximum number of attempts, and a backoff rate — Step Functions automatically re-invokes the state according to this policy whenever a matching error occurs, with no retry loop needed inside the underlying Lambda function's code. A Catch field similarly lists error types, but instead of retrying, routes execution to a specified fallback state when a matching error occurs after retries (if any) are exhausted — commonly used to route a failure to a notification step, a compensating transaction, or a dead-letter-style holding state for manual investigation. Because these policies live in the state machine's declarative definition rather than scattered across individual function implementations, an entire workflow's error-handling behavior can be understood and audited by reading one definition, rather than reverse-engineering try/except blocks spread across many separate Lambda functions.

💬 Deep Dive with AI

Key points

  • Retry: automatically re-invokes a state on matching errors, per a configured interval/max-attempts/backoff policy
  • Catch: routes to a fallback state when an error occurs (after retries are exhausted, if configured)
  • Both are declared in the state machine definition, not hand-coded inside individual Lambda functions
  • Centralizes a workflow's entire error-handling behavior into one auditable, visual definition