AWS Step 函数将状态映射到活动

AWS Step functions map state with activities

AWS 文档中不清楚在步骤函数中对映射状态的动态并行支持是否只能与 lambda 一起使用,或者它是否也可以作为嵌套工作流的一部分映射到活动。有人用它来并行化不同的异步活动吗?

您可以在 Map State 中使用 Amazon States Language 中定义的任何 State,如果您想知道自己不限于单个 State,您可以在 Map 的 Iterator 字段中定义完整的工作流程状态。把它想象成在你的地图状态中定义一个新的状态机,这类似于一个并行状态,除了每个分支都是相同的,分支的数量是基于你的数组。

{
  "Comment": "An example of the Amazon States Language using a map state to process elements of an array with a max concurrency of 2.",
  "StartAt": "HardcodedInputsState",
  "States": {
    "HardcodedInputsState": {
      "Type": "Pass",
      "Result": {
        "array": [
          "Iterate",
          "Over",
          "This",
          "Array"
        ]
      },
      "Next": "Map"
    },
    "Map": {
      "Type": "Map",
      "ItemsPath": "$.array",
      "ResultPath": "$.array",
      "MaxConcurrency": 2,
      "Next": "Final State",
      "Parameters": {
        "Value.$": "$$.Map.Item.Value",
        "Index.$": "$$.Map.Item.Index"
      },
      "Iterator": {
        "StartAt": "You",
        "States": {
          "You": {
            "Type": "Pass",
            "Next": "Can"
          },
          "Can": {
            "Type": "Pass",
            "Next": "Do"
          },
          "Do": {
            "Type": "Pass",
            "Next": "Anything"
          },
          "Anything": {
            "Type": "Pass",
            "End": true
          }
        }
      }
    },
    "Final State": {
      "Type": "Pass",
      "End": true
    }
  }
}