在 AWS Step Functions Catch 方法的下游步骤中使用输出变量

Use output variable in downstream step on AWS Step Functions Catch method

我正在尝试使用 API 网关和简单的 POST/DELETE 端点来实现 Saga 模式。我首先创建一所大学,然后是引用第一个的地址,如果此步骤失败,我想删除该大学。我不知道如何将大学的 id 传递给创建地址的 catch,所以我可以使用大学的 DB id 调用大学的 DELETE 端点。这是我目前的流程:

{
  "Comment": "Calling ECS service that calls another service",
  "StartAt": "Create University",
  "States": {
    "Create University": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
        "Method": "POST",
        "Path": "universities",
        "Headers": {
          "Content-Type": [
            "application/json"
          ]
        },
        "RequestBody": {
          "name.$": "$.name",
          "country.$": "$.country"
        },
        "AuthType": "NO_AUTH"
      },
      "ResultSelector": {
        "id.$": "$.ResponseBody.id"
      },
      "Next": "Create Address"
    },
    "Create Address": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
        "Method": "POST",
        "Path.$": "States.Format('/universities/{}/address', $.id)",
        "Headers": {
          "Content-Type": [
            "application/json"
          ]
        },
        "RequestBody": {
          "address.$": "$$.Execution.Input.address"
        },
        "AuthType": "NO_AUTH"
      },
      "ResultPath": "$.id",
      "Catch": [
        {
          "ErrorEquals": [
            "States.ALL"
          ],
          
          "Next": "Delete University"
        }
      ],
      "End": true
    },
    "Delete Address": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
        "Method": "DELETE",
        "Path.$": "States.Format('/universities/{}/address', $.id)",
        "Headers": {
          "Content-Type": [
            "application/json"
          ]
        },
        "AuthType": "NO_AUTH"
      },
      "Next": "Delete University"
    },
    "Delete University": {
      "Type": "Task",
      "Resource": "arn:aws:states:::apigateway:invoke",
      "Parameters": {
        "ApiEndpoint": "xxxxxxxxxxx.amazonaws.com",
        "Method": "DELETE",
        "Path.$": "States.Format('/universities/{}', $.id)",
        "Headers": {
          "Content-Type": [
            "application/json"
          ]
        },
        "AuthType": "NO_AUTH"
      },
      "End": true
    }
  }
}

我需要使用 Create University 步骤返回的 ID 进入 Delete University 步骤,这样我才能正确调用 DELETE 端点。有什么想法吗?

docs: Use ResultPath in a Catch to include the error with the original input, instead of replacing it.

"Catch": [
  {
    "ErrorEquals": [ "States.ALL"],
    "ResultPath": "$.error",
    "Next": "Delete University"
  }
],