簡體   English   中英

在 Step 函數中訪問 Map State ( item )

[英]Access Map State ( item ) in Step functions

我正在嘗試訪問我正在使用 Map state 迭代的項目屬性。我不斷收到此錯誤:

Value ($['Map'].snapshot_id.S) for parameter snapshotId is invalid. Expected: 'snap-...'. (Service: Ec2, Status Code: 400, Request ID: 6fc02935-c161-49df-8606-bc6f3e2934a6)

我瀏覽了文檔,它似乎建議使用$.Map.snapshot_id.S進行訪問,但似乎不起作用。 同時,Map的一個輸入項是:

{
  "snapshot_id": {
    "S": "snap-01dd5ee46df84119e"
  },
  "file_type": {
    "S": "bash"
  },
  "id": {
    "S": "64e6893261d94669b7a8ca425233d68b"
  },
  "script_s3_link": {
    "S": "df -h"
  }
}

Map state 定義:

    "Map": {
          "Type": "Map",
          "ItemProcessor": {
            "ProcessorConfig": {
              "Mode": "INLINE"
            },
            "StartAt": "Parallel State",
            "States": {
              "Parallel State": {
                "Comment": "A Parallel state can be used to create parallel branches of execution in your state machine.",
                "Type": "Parallel",
                "Branches": [
                  {
                    "StartAt": "CreateVolume",
                    "States": {
                      "CreateVolume": {
                        "Type": "Task",
                        "Parameters": {
                          "AvailabilityZone": "us-east-2b",
                          "SnapshotId": "$$.Map.snapshot_id.S"
                        },
                        "Resource": "arn:aws:states:::aws-sdk:ec2:createVolume",
                        "Next": "AttachVolume"
                      },
                      "AttachVolume": {
                        "Type": "Task",
                        "Parameters": {
                          "Device": "MyData",
                          "InstanceId": "MyData",
                          "VolumeId": "MyData"
                        },
                        "Resource": "arn:aws:states:::aws-sdk:ec2:attachVolume",
                        "End": true
                      }
                    }
                  }
                ],
                "End": true
              }
            }
          },
          "Next": "Final Result",
          "ItemsPath": "$.Items",
          "MaxConcurrency": 40
        },

TL;DR "SnapshotId.$": "$.snapshot_id"

默認情況下,每個內聯 map 迭代的輸入都是ItemsPath數組中的一項,可以簡單地通過$訪問。

您的 state 機器定義暗示$.Items是具有snapshot_id鍵(和其他鍵)的對象數組。 如果是這樣,則每次迭代的快照 ID 都位於$.snapshot_id

最后,將.$添加到參數名稱 ( SnapshotId.$ ) 告訴 Step Functions 該值不是文字,而是要替換的路徑值

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM