AWS Step Function - 将动态值添加到传递状态类型

AWS Step Function - Adding dynamic value to Pass state type

我的状态机中定义了以下状态。

 "loop":{
      "Type": "Pass",
      "Result":{
        "totalCount": "$.newFieldsResponse.body.count",
        "currentCount": 0,
        "step": 1
      },
      "ResultPath": "$.iteration",
      "Next":"iterateLoop"
    },

我希望状态的输出是:

"newFieldsResponse": {
      "isSuccess": true,
      "error": "",
      "body": {
        "count": 2,
        "fields": [...]
      }
    },
    "iteration": {
      "totalCount": 5,
      "currentCount": 0,
      "step": 1
    }
  }

将迭代 属性 添加到输入中,totalCount 属性 将设置为字段数组中的项目数。

但是,"iteration" 属性 的输出设置为:

"iteration": {
      "totalCount": "$.newFieldsResponse.body.count",
      "currentCount": 0,
      "step": 1
    }

看起来值“$.newFieldsResponse.body.count”没有得到解析,而是按原样输出。

我做错了什么吗?有人可以就如何让它发挥作用提出建议吗?

看起来这不可能。 我所做的解决方法是使用 "Parameters" 属性。来自 AWS 文档: "For key-value pairs where the value is selected using a path, the key name must end in *.$. ".

所以解决了上面的问题:

  1. 更改 Pass 状态以删除任何动态值引用
"loop":{
      "Type": "Pass",
      "Result":{
        "currentCount": 0,
        "step": 1
      },
      "ResultPath": "$.iteration",
      "Next":"iterateLoop"
    },
  1. 创建参数 属性,我需要以下值:
 "iterateLoop":{
      "Type":"Task",
      "Resource": "arn:aws:lambda:....r",
      "Parameters":{
        "totalCount.$": "$.newFieldsResponse.body.count",
        "currentCount.$": "$.iteration.currentCount",
        "step.$": "$.iteration.step"
      },
      "ResultPath": "$.iteration",
      "Next":"continueLoop"
    },

totalCount、currentCount 和 step 都是使用状态输入中的路径读取值。密钥需要在末尾附加“.$”。

这可以通过 "Parameters" in pass state

JSON

{
  "loop": {
    "Type": "Pass",
    "Parameters": {
      "totalCount": "$.newFieldsResponse.body.count",
      "currentCount": 0,
      "step": 1
    },
    "ResultPath": "$.iteration",
    "Next": "iterateLoop"
  }
}

在我弄明白之前,我也被困在了这个问题上。

可以使用传递状态,但@ankitkanojia 和@shashi 的答案需要稍作修改。

如果要使用输入路径,参数里面的key需要以".$"结尾("totalCount.$")

所以状态规范应该如下:

"loop":{
      "Type": "Pass",
      "Result":{
        "totalCount.$": "$.newFieldsResponse.body.count",
        "currentCount": 0,
        "step": 1
      },
      "ResultPath": "$.iteration",
      "Next":"iterateLoop"
    },

它结合了这里公开的两个解决方案:

  1. 在传递步骤中添加参数
  2. 在要传递的变量名中加入*.$:
 {
  "loop": {
    "Type": "Pass",
    "parameters": {
      "totalCount.$": "$.newFieldsResponse.body.count",
      "currentCount": 0,
      "step": 1
    },
    "ResultPath": "$.iteration",
    "Next": "iterateLoop"
  }
 }