AWS Step Function: custom end state for choices

Viewed 1385

I have a choice state like below:

"ChoiceStateX": {
  "Type": "Choice",
  "Choices": [
    {
      "Not": {
        "Variable": "$.type",
        "StringEquals": "Private"
      },
      "Next": "Public"
    },
    {
      "Variable": "$.value",
      "NumericEquals": 0,
      "Next": "MyEndState"  // can I do something like this? 
    },
}

For the state with $.value == 0, I need to end the step function, because Choices does NOT support End: true, I need explicitly to have something like MyEndState.

So how should I define MyEndState inside the step function? Is there a such way?

2 Answers

What I do in that case is add a PassState that has End: true, and send the Next of the ChoiceState to that state.

A state of "Type": "Succeed" seems specifically designed for this purpose.

The AWS documentation of the Succeed state explains that it is a useful target for Choice state branches that don't do anything but stop the execution (they are terminal states, they have no Next field, and don't need an End field).

So I would just add:

"SuccessState": {
  "Type": "Succeed"
}

And (instead of MyEndState) point that Choice's "Next" to "SuccessState".

Related