Search code examples
typescriptaws-cdkaws-step-functions

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


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:

Step Function AWS

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
  }

Solution

  • 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.