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

时间:2020-03-25 19:37:13

标签: aws-step-functions

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

1 个答案:

答案 0 :(得分:0)

您可以在地图状态内使用Amazon States Language中定义的任何状态,并且如果您想知道自己不限于一个州,则可以在地图状态的Iterator字段内定义完整的工作流程。可以将其视为在Map State中定义一个新的State Machine,这与Parallel State类似,不同之处在于每个分支都是相同的,并且分支的数量取决于您的数组。

{
  "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
    }
  }
}