簡體   English   中英

CDK 傳遞步驟:如何在輸入 object 的根目錄添加屬性

[英]CDK pass step: How to add properties at root of input object

我想向輸入數據的根目錄添加一些屬性。 假設我們有

{
  "f1": 1,
  "cx": {
          "cxf1": 113,
          "cxf2": "f23"
        },
  "cx2": {
          "cxf12": 11,
          "cxf22": "f2"
        }
}

我想創建 CDK Pass 步驟以將簡單值和復雜值添加到輸入的根並進一步傳遞組合數據。 我應該有 output 為:

{
  "f1": 1,
  "cx": {
          "cxf1": 113,
          "cxf2": "f23"
        },
  "cx2": {
          "cxf12": 11,
          "cxf22": "f2"
        },
  "out1": "simple",
  "out2complex": {
          "f1A": 111,
          "f2A": "f22"
        }             
}

我嘗試了 inputPath、outputhPath、resultpath 的 Whatevr 組合不起作用。 它僅在指定結果路徑時才有效,並且我的結果將 go 到路徑作為復雜元素。
我認為這是設計使然。 如果我只指定 result ,這意味着它將覆蓋輸入。
有沒有辦法將簡單屬性和復雜屬性添加到輸入 object 的根並進一步傳遞?

我們需要將 pass 步驟的 output 與resultPath一起傳遞

假設通過步驟 output 是一個字符串simple ,它將附加到現有輸入 Json 與 key out1resultPath: "$.out1"

const firstStep = new stepfunctions.Pass(this, "Build Out1", {
  result: stepfunctions.Result.fromString("simple"),
  resultPath: "$.out1",
});

const secondStep = new stepfunctions.Pass(this, "Build out2complex", {
  result: stepfunctions.Result.fromObject({
    f1A: 111,
    f2A: "f22",
  }),
  resultPath: "$.out2complex",
});
const def = firstStep.next(secondStep);

new stepfunctions.StateMachine(this, "StateMachine", {
  definition: def,
});

在此處輸入圖像描述

輸入:

{
  "f1": 1,
  "cx": {
    "cxf1": 113,
    "cxf2": "f23"
  },
  "cx2": {
    "cxf12": 11,
    "cxf22": "f2"
  }
}

Output:

{
  "f1": 1,
  "cx": {
    "cxf1": 113,
    "cxf2": "f23"
  },
  "cx2": {
    "cxf12": 11,
    "cxf22": "f2"
  },
  "out1": "simple",
  "out2complex": {
    "f1A": 111,
    "f2A": "f22"
  }
}

暫無
暫無

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

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