gpt4 book ai didi

amazon-web-services - AWS 状态机 ASL : Use the Result Selector only if data is returned

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

我正在尝试配置任务状态以查找组织,如果找到组织,结果选择器将选择名称、ID 和创建时间。然后,这将被添加回组织节点 (ResultPath) 下的工单。

我遇到的问题是,如果找不到组织,那么状态机的执行将被取消,因为结果选择器正试图选择结果中不存在的节点。有谁知道是否有办法仅在返回数据时使用结果选择器?即使未找到组织,我也希望状态机继续运行。

"Find Organization": {
"Type": "Task",
"Resource": "${aws_lambda_function.test_function.arn}",
"Next": "Find User Account",
"Parameters": {
"name": "FindOrganization",
"request.$": "$.item"
},
"ResultSelector": {
"name.$": "$.name",
"id.$": "$.id",
"createTime.$": "$.createTime"
},
"ResultPath": "$.org",
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"ResultPath": "$.error",
"Next": "Publish SNS Failure"
}
]
}

最佳答案

这正是 Choice State 的时候开始发挥作用。

对原始 ASL 定义的示例修改是

{
"Comment": "An example of the Amazon States Language using a choice state.",
"StartAt": "Find Organization",
"States": {
"Find Organization": {
"Type": "Task",
"Resource": "arn:aws:states:::lambda:invoke",
"Next": "Check If Organization Exists",
"Parameters": {
"name": "FindOrganization",
"request.$": "$.item"
},
"Catch": [
{
"ErrorEquals": [
"States.ALL"
],
"ResultPath": "$.error",
"Next": "Publish SNS Failure"
}
]
},
"Check If Organization Exists": {
"Type": "Choice",
"Choices": [
{
"Variable": "$",
"IsNull": false,
"Next": "Organization Exists"
},
{
"Variable": "$",
"IsNull": true,
"Next": "Organization Not Exists"
}
],
"Default": "Organization Exists"
},
"Organization Exists": {
"Type": "Pass",
"Parameters": {
"name.$": "$.name",
"id.$": "$.id",
"createTime.$": "$.createTime"
},
"ResultPath": "$.org",
"Next": "Find User Account"
},
"Organization Not Exists": {
"Type": "Fail"
},
"Find User Account": {
"Type": "Succeed"
},
"Publish SNS Failure": {
"Type": "Fail"
}
}
}

enter image description here

关于amazon-web-services - AWS 状态机 ASL : Use the Result Selector only if data is returned,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64812112/

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