Choice state
A Choice state adds conditional logic to a ZIS flow.
"PickChoice":{
"Type":"Choice",
"Choices":[
{
"Variable":"$.input.value",
"StringEquals":"Choice A",
"Next":"NextStateA"
},
{
"Variable":"$.input.value",
"StringEquals":"Choice B",
"Next":"NextStateB"
}
],
"Default":"NextStateC"
}
Supported properties
In addition tocommon state properties, a Choice state supports the following properties.
Name | Type | Mandatory | Description |
---|---|---|---|
Choices | array | true | Array ofchoice ruleobjects. These rules determine the next state in the ZIS flow. Must contain at least one choice rule object |
Default | string | false | Next state to run if no choice rules inChoices are true |
Choice rules
A choice rule object contains a boolean expression. The expression is acomparisonthat evaluates to true or false. When run, the Choice state evaluates each rule in theChoices
array in the order provided. The ZIS flow runs theNext
state of the first rule that evaluates to true. If no rule in theChoices
array is true, the flow runs theDefault
state.
A choice rule object requires the following properties:
- A
Variable
that contains aJSON reference pathto an input value - Acomparison operator
- The
Next
state to run in the ZIS flow if the rule evaluates to true
The object also supports an optionallogical operator.
Comparisons
To evaluate a rule, a Choice state compares the inputVariable
to the value of the comparison operator. For example, the following state compares$.ticket.priority
to a staticStringEquals
value.
"Choice.CheckTicketPriority":{
"Type":"Choice",
"Choices":[
{
"Variable":"$.ticket.priority",
"StringEquals":"Urgent",
"Next":"EscalateTicketStep"
}
],
"Default":"NormalTicketStep"
}
To compare the input variable to a reference path, appendPath
to theStringEquals
key.
Note:Some comparison operators don't support aPath
suffix. Seecomparison operators.
"Choice.CheckTicketPriority":{
"Type":"Choice",
"Choices":[
{
"Variable":"$.ticket.priority",
"StringEqualsPath":"$.settings.ticket_priority",
"Next":"EscalateTicketStep"
}
],
"Default":"NormalTicketStep"
}
Comparison operators
A Choice state supports the following comparison operators.
Comparison operator | Path comparison operator |
---|---|
StringEquals | StringEqualsPath |
StringLessThan | |
StringGreaterThan | |
StringLessThanEquals | |
StringGreaterThanEquals | |
NumericEquals | NumericEqualsPath |
NumericLessThan | NumericLessThanPath |
NumericGreaterThan | NumericGreaterThanPath |
NumericLessThanEquals | NumericLessThanEqualsPath |
NumericGreaterThanEquals | NumericGreaterThanEqualsPath |
BooleanEquals | BooleanEqualsPath |
TimestampEquals | |
TimestampLessThan | |
TimestampGreaterThan | |
TimestampLessThanEquals | |
TimestampGreaterThanEquals | |
IsPresent | |
IsNull |
Logical operators
Use logical operators to combine or negate choice rules in a choice rule object. A Choice state supports the following logical operators:
Not
And
Or
Not
example:
"Choice.TicketNotClosed":{
"Type":"Choice",
"Choices":[
{
"Not":{
"Variable":"$.jq_result",
"StringEquals":"Closed"
},
"Next":"ActiveTicketStep"
}
],
"Default":"ClosedTicketStep"
}
And
example:
"Choice.WaitingUrgentTicket":{
"Type":"Choice",
"Choices":[
{
"And":[
{
"Variable":"$.ticket.status",
"StringEquals":"New"
},
{
"Variable":"$.ticket.priority",
"StringEquals":"Urgent"
}
],
"Next":"EscalateTicketStep"
}
],
"Default":"NormalTicketStep"
}
Or
example:
"Choice.TicketTopPriorities":{
"Type":"Choice",
"Choices":[
{
"Or":[
{
"Variable":"$.ticket.priority",
"StringEquals":"High"
},
{
"Variable":"$.ticket.priority",
"StringEquals":"Urgent"
}
],
"Next":"EscalateTicketStep"
}
],
"Default":"NormalTicketStep"
}
Example
For an example of a Choice state in a ZIS flow, seeUsing conditional branching in a ZIS flow.
Limitations
A ZIS Choice state doesn't support all comparison operators from theAmazon State Language. For supported operators, seeComparison operators.