Retries & Error Handling
Make workflows resilient with Retry and Catch, without writing retry loops yourself.
1 min read
Any Task can declare how to handle failures:
- Retry: try again with exponential backoff (and optional jitter) for specific errors.
- Catch: when retries run out, go to a fallback state instead of failing the whole execution.
Try it
JSON
"Summarize": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Parameters": { "FunctionName": "notesnap-summarize", "Payload.quot;: "quot; },
"Retry": [
{
"ErrorEquals": ["Lambda.TooManyRequestsException", "Lambda.ServiceException"],
"IntervalSeconds": 2,
"BackoffRate": 2.0,
"MaxAttempts": 4,
"JitterStrategy": "FULL"
}
],
"Catch": [
{
"ErrorEquals": ["States.ALL"],
"ResultPath": "$.error",
"Next": "MarkAsFailed"
}
],
"Next": "SaveSummary"
}This retries throttling errors after about 2, 4, 8, and 16 seconds (with randomness from jitter), and sends
any remaining failure to a MarkAsFailed state with the error details in $.error.
Built-in error names
States.ALL: matches any errorStates.TaskFailed: the task failedStates.Timeout: the task exceededTimeoutSeconds- Your own: raise a custom exception in Lambda (e.g.
class NoteTooLong(Exception)) and match"NoteTooLong"
Tip
Retry only transient errors like throttling or timeouts. Retrying a validation error four times just fails four times slower.
Key takeaways
- Retry handles transient failures with exponential backoff and jitter.
- Catch routes failures to a recovery or cleanup path.
- Retry transient errors only, and catch everything else.
Check your understanding
Pick an answer to see the explanation.
1. Your task occasionally gets throttled. What's the right fix in the workflow?