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 inChoicesare 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 theChoicesarray in the order provided. The ZIS flow runs theNextstate of the first rule that evaluates to true. If no rule in theChoicesarray is true, the flow runs theDefaultstate.

A choice rule object requires the following properties:

The object also supports an optionallogical operator.

Comparisons

To evaluate a rule, a Choice state compares the inputVariableto the value of the comparison operator. For example, the following state compares$.ticket.priorityto a staticStringEqualsvalue.

             
"Choice.CheckTicketPriority":{"Type":"Choice","Choices":[{"Variable":"$.ticket.priority","StringEquals":"Urgent","Next":"EscalateTicketStep"}],"Default":"NormalTicketStep"}

To compare the input variable to a reference path, appendPathto theStringEqualskey.

Note:Some comparison operators don't support aPathsuffix. 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

Notexample:

             
"Choice.TicketNotClosed":{"Type":"Choice","Choices":[{"Not":{"Variable":"$.jq_result","StringEquals":"Closed"},"Next":"ActiveTicketStep"}],"Default":"ClosedTicketStep"}

Andexample:

             
"Choice.WaitingUrgentTicket":{"Type":"Choice","Choices":[{"And":[{"Variable":"$.ticket.status","StringEquals":"New"},{"Variable":"$.ticket.priority","StringEquals":"Urgent"}],"Next":"EscalateTicketStep"}],"Default":"NormalTicketStep"}

Orexample:

             
"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.