Certopolis

AWS Certified Developer – Associate

Step Functions Retry and Catch error handling for DVA-C03

The AWS Step Functions Developer Guide says that when a state reports an error, the whole execution fails by default. Task, Parallel and Map states can add a Retry array of retriers and a Catch array of catchers. Step Functions applies a matching retrier first, and a catcher only when retries do not resolve the error.

How does Retry work?

Retry is an array of retriers. When the state reports an error, Step Functions scans the retriers in the order listed and uses the first whose ErrorEquals array contains the error name. Put specific error names before wildcards, or the wildcard retrier handles them.

IntervalSeconds is the wait before the first retry and defaults to 1. MaxAttempts defaults to 3, and a value of 0 means the error is never retried. BackoffRate multiplies the interval after each attempt and defaults to 2.0. With an interval of 3, three attempts and a rate of 2, the waits are 3, 6 and 12 seconds.

MaxDelaySeconds caps how far the interval can grow. JitterStrategy accepts FULL or NONE, with NONE as the default. FULL randomizes each wait between 0 and the computed interval, which spreads out retries that would otherwise happen at the same moment.

Retries are treated as state transitions for billing.

How does Catch work?

Catch is an array of catchers. Each has ErrorEquals, a required Next that names the fallback state, and an optional ResultPath. Step Functions scans catchers in order when there is no Retry field or when retries fail to resolve the error.

The fallback state receives the error output, which usually contains a Cause field. In a JSONPath workflow, a catcher without ResultPath uses the default $, so the error output overwrites the whole state input. Setting a path such as $.error-info adds the error output to the original input, and the fallback state receives both.

Catchers handle errors inside Task, Parallel and Map states. They are not available for a top-level execution failure.

Which error names matter?

Error names are case-sensitive strings. Built-in names start with States., and custom error names cannot use that prefix.

States.ALL is a wildcard. It must appear alone in its ErrorEquals array and in the last retrier or catcher. It does not catch States.DataLimitExceeded or States.Runtime. States.DataLimitExceeded can be caught or retried only by naming it explicitly, and States.Runtime is not retriable and always fails the execution.

States.TaskFailed also works as a wildcard and matches any error except States.Timeout. States.Timeout is reported when a Task runs longer than TimeoutSeconds or misses a heartbeat for longer than HeartbeatSeconds. For Lambda tasks, AWS advises handling Lambda.ServiceException and Lambda.SdkClientException.

Where the exam catches people

  • Believing Step Functions picks the most specific retrier: it uses the first match in array order, so a States.TaskFailed retrier listed first takes a custom error.
  • Believing MaxDelaySeconds spreads out simultaneous retries: it only caps the wait. JitterStrategy set to FULL randomizes it.
  • Believing a catcher keeps the state input by default: in JSONPath the default ResultPath of $ replaces the input with the error output.
  • Believing States.ALL catches everything: it does not catch States.Runtime or States.DataLimitExceeded.
  • Believing States.TaskFailed covers timeouts: it matches any error except States.Timeout.

Written from these sources

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. An AWS Step Functions state machine calls an AWS Lambda function that intermittently fails with a transient error, and any failure currently ends the whole execution. The developer needs the task retried a few times with increasing waits, and the workflow to continue to a cleanup state when the retries are exhausted. Which solution will meet these requirements?

    Right. In the game that’s Renown for your Development with AWS Services building.

    Not that one: D is right. In the game your Development with AWS Services building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Step Functions applies retriers first and falls through to the matching catcher only when retries fail.

    Written from docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html

  2. A Task state in an AWS Step Functions state machine invokes an AWS Lambda function against a partner API. The function reports a RateLimited error when the partner throttles it. The state's Retry array holds a retrier for States.TaskFailed that makes a couple of quick attempts, followed by a retrier for RateLimited that waits far longer between attempts. When the partner throttles, the state gives up after the quick attempts. Throttled calls must use the longer schedule. Which solution will resolve this issue?

    Right. In the game that’s Renown for your Development with AWS Services building.

    Not that one: A is right. In the game your Development with AWS Services building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    The first retrier here names States.TaskFailed, which the documentation describes as a wildcard that matches any known error name except for States.Timeout, so it matches RateLimited and the scan stops there. The longer retrier never applies. Placing the RateLimited retrier ahead of the wildcard makes the specific policy the first match for that error, while every other error continues to fall through to the wildcard retrier behind it.

    Written from docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html

  3. An AWS Step Functions Standard workflow calls a third-party API from a Task state. The retrier on that state already handles the throttling error with an IntervalSeconds value of 2 and a BackoffRate value of 2. Thousands of executions run at once, and their retry attempts still reach the API in synchronized waves. Which solution will resolve this issue?

    Right. In the game that’s Renown for your Development with AWS Services building.

    Not that one: C is right. In the game your Development with AWS Services building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    With FULL, a two-second wait becomes a random wait between zero and two seconds, and the wave spreads out. The runner-up, MaxDelaySeconds, caps how long the interval can grow but leaves every execution waiting the identical capped time, so the attempts stay synchronized. Raising BackoffRate makes the waves later and larger, not wider.

    Written from docs.aws.amazon.com/step-functions/latest/dg/concepts-error-handling.html

Ask for something