AWS Step Function 中基于数组中项目数的分支流程

Branch Flow in AWS Step Function Based on Number of Items in Array

我想根据数组中的项数来分支 AWS 状态机的流程。如果数组有 0 个项目,我想结束流程。如果它有超过 0 个项目,我想做一些事情。

例如,我想做如下事情:

{
  "StartAt": "IsBig",
  "States": {
    "IsBig": {
      "Type": "Choice",
      "Choices": [
        {
          "Variable": "$.things.length",
          "NumericGreaterThan": 0,
          "Next": "Big"
        }
      ],
      "Default": "Small"
    },
    "Big": {
      "Type": "Pass",
      "Result": "1",
      "End": true
    },
    "Small": {
      "Type": "Pass",
      "Result": "0",
      "End": true
    }
  }
}

然后我会在执行时传递以下内容:

{ "things": [1, 2, 3] }

我希望 IsBig 然后调用 Big 并结束。

有没有办法用 AWS 状态语言做到这一点?

如果我不能,我将创建一个获取数组长度的 Lambda。我只是好奇。

答案是"no"。您不能 运行 来自 "Variable": "$.things.length" 属性 的函数。

Variable 字段中的值是一个....变量。这不是一个表达。 docs 不显示任何表达式求值语法。所以,长话短说,你不能做我想做的事。