The steps we will do in this section:
{
"StartAt": "Check Name",
"States": {
"Check Name": {
"Type": "Task",
"Parameters": {
"command": "CHECK_NAME",
"data": {
"name.$": "$.application.name"
}
},
"Resource": "${DataCheckingFunctionArn}",
"ResultPath": "$.checks.name",
"Next": "Check Address"
},
"Check Address": {
"Type": "Task",
"Parameters": {
"command": "CHECK_ADDRESS",
"data": {
"address.$": "$.application.address"
}
},
"Resource": "${DataCheckingFunctionArn}",
"ResultPath": "$.checks.address",
"Next": "Review Required?"
},
"Review Required?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.checks.name.flagged",
"BooleanEquals": true,
"Next": "Pending Review"
},
{
"Variable": "$.checks.address.flagged",
"BooleanEquals": true,
"Next": "Pending Review"
}
],
"Default": "Approve Application"
},
"Pending Review": {
"Type": "Pass",
"End": true
},
"Approve Application": {
"Type": "Pass",
"End": true
}
}
}
sam deploy
We just added two new statuses to our workflow: Review Required and Pending Review. Review Requried state? Checks its input (which is the output from Check Address state) and will run through a series of checks ( rules ).
You can see that there are a series of two selection rules in the definition of the state, each specifying the state to go to the next if its rule matches successfully. There is also a default state name specified to switch to in case there are no matching rules.
One of our Selection rules says that if the value inside the input at checks.name.flagged is true, the next state will be Pending Review. The other selection rule is the same, check checks.address.flagged to see if it is true, in which case it goes to Pending Review as well. Finally, the default value of our Choice state indicates that if no selection rule matches, the state machine will transition to the Approve Application state.
The next step we will try to execute the workflow to see the results.
If you’re more interested in the behavior and comparison types supported by Choice state, check out the developer guide at https://docs.aws.amazon.com/step-functions /latest/dg/amazon-states-language-choice-state.html