gpt4 book ai didi

aws-step-functions - 如何使用 Choice 来测试输入数组是否包含给定的过滤器?

转载 作者:行者123 更新时间:2023-12-05 04:49:24 26 4
gpt4 key购买 nike

给定一个 Map 状态,输出是一个类似于以下的数组:

[
{
"ProcessState": {
"Status": "SUCCESS"
}
},
{
"ProcessState": {
"Status": "SUCCESS"
}
},
{
"ProcessState": {
"Status": "FAILURE"
}
}
]

我希望能够测试是否存在 Status = 'FAILURE' 的元素。我尝试使用具有以下选择的 Choice:

{
"Variable": "$..ProcessState[?(Status == FAILURE)]",
"IsPresent": true,
"Next": "Items Contained Failure"
}

尝试此操作时,我得到 Value is not a Reference Path: Illegal '..' ...

我正在考虑尝试使用 Pass 作为中间步骤,但我认为这只会失败,因为如果没有条目匹配,它就找不到任何东西。

最佳答案

这已通过让 Map 状态 ResultSelector 执行过滤来解决。

"ResultSelector": {
"QueueFailures.$": "$[?(@.ProcessState.Status == 'FAILED')]"
},
"ResultPath": "$.ProcessResult"

Choice 状态现在可以只测试是否存在第一个失败项。

"Test Queue Failures": {
"Type": "Choice",
"Default": "Mark Decision Run Ready",
"Choices": [
{
"Variable": "$.ProcessResult.QueueFailures[0]",
"IsPresent": true,
"Next": "Queue Contains Failures"
}
]
}

关于aws-step-functions - 如何使用 Choice 来测试输入数组是否包含给定的过滤器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67603012/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com