如何接收 AWS CDK 中 new StepFunctionsStartExecution 的响应?

huangapple go评论68阅读模式
英文:

How Do I Receive The Response From new StepFunctionsStartExecution In AWS CDK?

问题

使用场景:

  1. 在步骤函数1中遍历子项
  2. 将每个JSON对象发送到步骤函数2
  3. 在步骤函数2结束时,它会收到来自第三方API的响应
  4. 在步骤函数1中使用该API响应

图像:

如何接收 AWS CDK 中 new StepFunctionsStartExecution 的响应?

代码:

this.mapOverChildren = new Map(this, "Map Over Children", {
  itemsPath: "$.data.children",
  maxConcurrency: 1,
  resultPath: "$.children",
});

this.mapOverChildren.iterator(new StepFunctionsStartExecution(this, 'Send Data to Step Function 2', {
  stateMachine: stepFunction.Two,
  integrationPattern: IntegrationPattern.REQUEST_RESPONSE,
  resultPath: "$.stepFunctionTwoResponse"
});

目前,resultPath 只显示有关步骤函数执行的信息。如何从步骤函数2中获取数据?

resultPath:

{
    "ExecutionArn": "xxxxxxxxxxxx",
    "SdkHttpMetadata": {
      "AllHttpHeaders": {
        "x-amzn-RequestId": [
          "xxxxxxxxxxx"
        ],
        "Content-Length": [
          "000"
        ],
        "Date": [
          "Thu, 23 Feb 2023 11:24:14 GMT"
        ],
        "Content-Type": [
          "application/xxxxxxxxxxxxxxxxxxxxxxx"
        ]
      },
      "HttpHeaders": {
        "Content-Length": "111",
        "Content-Type": "application/xxxxxxxxxxxxxxxxxxxxxxx",
        "Date": "Thu, 23 Feb 2023 11:24:14 GMT",
        "x-amzn-RequestId": "xxxxxxxxxxxxxxxxxxxxxxx"
      },
      "HttpStatusCode": 200
    },
    "SdkResponseMetadata": {
      "RequestId": "xxxxxxxxxxxxxxxxxxxxxxx"
    },
    "StartDate": 1677151454840
  }
英文:

Use-Case:

  1. Map over the children in Step Function 1
  2. Send each JSON object to Step Function 2
  3. At the end of Step Function 2, it receives a response from a third-party API
  4. Use that API response in Step Function 1

Image:

如何接收 AWS CDK 中 new StepFunctionsStartExecution 的响应?

Code:

this.mapOverChildren = new Map(this, "Map Over Children", {
  itemsPath: "$.data.children",
  maxConcurrency: 1,
  resultPath: "$.children",
});

this.mapOverChildren .iterator(new StepFunctionsStartExecution(this, 'Send Data to Step Function 2', {
  stateMachine: stepFunction.Two,
  integrationPattern: IntegrationPattern.REQUEST_RESPONSE,
  resultPath: "$.stepFunctionTwoResponse"
});

At the momement, the resultPath is just showing information about the step function execution. How do I get the data back from Step Function 2?

resultPath:

{
    "ExecutionArn": "xxxxxxxxxxxx",
    "SdkHttpMetadata": {
      "AllHttpHeaders": {
        "x-amzn-RequestId": [
          "xxxxxxxxxxx"
        ],
        "Content-Length": [
          "000"
        ],
        "Date": [
          "Thu, 23 Feb 2023 11:24:14 GMT"
        ],
        "Content-Type": [
          "application/xxxxxxxxxxxxxxxxxxxxxxx"
        ]
      },
      "HttpHeaders": {
        "Content-Length": "111",
        "Content-Type": "application/xxxxxxxxxxxxxxxxxxxxxxx",
        "Date": "Thu, 23 Feb 2023 11:24:14 GMT",
        "x-amzn-RequestId": "xxxxxxxxxxxxxxxxxxxxxxx"
      },
      "HttpStatusCode": 200
    },
    "SdkResponseMetadata": {
      "RequestId": "xxxxxxxxxxxxxxxxxxxxxxx"
    },
    "StartDate": 1677151454840
  }

答案1

得分: 2

REQUEST_RESPONSE是一个错误的集成模式,如果您想等待子步骤函数完成并使用其结果,应使用RUN_JOB

英文:

https://docs.aws.amazon.com/step-functions/latest/dg/connect-to-resource.html

REQUEST_RESPONSE is the wrong integration pattern to use if you want to wait for the sub stepfunction to finish and use its result, use RUN_JOB instead.

huangapple
  • 本文由 发表于 2023年2月23日 19:33:16
  • 转载请务必保留本文链接:https://go.coder-hub.com/75544256.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定