AWS Step function中,Choice状态不支持Field参数。如果需要添加Field参数,可以将Choice状态嵌套在Parallel状态内部,然后通过Parallel状态的ResultPath参数来实现。
示例代码:
{
"ParallelState": {
"Type": "Parallel",
"ResultPath": "$.result",
"Branches": [
{
"StartAt": "ChoiceState",
"States": {
"ChoiceState": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.field",
"NumericEquals": 1,
"Next": "State1"
},
{
"Variable": "$.field",
"NumericEquals": 2,
"Next": "State2"
}
],
"Default": "DefaultState"
},
"State1": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:111111111111:function:Function1",
"End": true
},
"State2": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:111111111111:function:Function2",
"End": true
},
"DefaultState": {
"Type": "Fail",
"Error": "DefaultStateError",
"Cause": "Invalid field value"
}
}
}
],
"Next": "NextState"
},
"NextState": {
"Type": "Task",
"Resource": "arn:aws:lambda:us-east-1:111111111111:function:NextFunction",
"End": true
}
}
以上示例中,我们通过Parallel状态来嵌套Choice状态,并通过ResultPath参数来指定Parallel状态的输出结果路径。在Choice状态内部,我们使用Variable参数来指定比较的字段,NumericEquals参数来指定比较条件,以及Next参数来指定下一个执行状态。如果字段的值都不符合条件,则进入Default状态。最后,我们通过Next参数将Parallel状态连接到下一个状态。