CDK 通过步骤:如何在输入对象的根目录添加属性

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 传递步骤以将简单值和复杂值添加到输入的根并进一步传递组合数据。我应该输出为:

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

我尝试了 inputPath、outputhPath、resultpath 的任何组合,但它不起作用。它仅在指定结果路径时有效,我的结果将作为复杂元素进入路径。
我认为这是设计使然。如果我指定 only result,这意味着它将覆盖输入。
有没有办法将简单 属性 和复杂 属性 添加到输入对象的根并进一步传递它?

我们需要通过resultPath

传递pass步骤的输出

假设通过步骤输出是一个字符串 simple ,它将附加到现有输入 Json 中,键 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"
  }
}

输出:

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