简体   繁体   中英

AWS Step Function synchronous Express Workflow calling from API Gateway and eliminating state machine details from response output

I have been messing around with step functions and found a great solution to orchestrating lambdas invoked from API gateway using the new synchronous express workflow, but have run into a problem where I cannot adjust the outer json on the output. I am able to modify everything in the "output" node of the json response using ResultPath and OutputPath, but everything else is retained and gets sent back to the user (Information that is not needed like BillingDetails).

I have to use HTTP API Gateway since it is the only one that can invoke step functions synchronously, and you cannot transform the response there, so I'm looking to see if there is any way to transform this response without having to create some additional layer on top of the Step Function, which would kind of defeat the whole purpose of using them in the first place.

How do I get the Step Function to only return the "output" json node and filter out everything else?

The Step function definition looks like this:

{
  "Comment": "Simple Lambda Function",
  "StartAt": "Invoke Lambda function",
  "States": {
    "Invoke Lambda function": {
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "ResultPath": "$",
      "OutputPath": "$.Payload",
      "Parameters": {
        "FunctionName": "LAMBDA ARN",
        "Payload": {
          "input.$": "$"
        }
      },
      "End": true
    }
  }
}

And the output from this state machine through API gateway produces the following:

{
    "billingDetails": {
        "billedDurationInMilliseconds": 500,
        "billedMemoryUsedInMB": 64
    },
    "executionArn": "ARN",
    "input": "{\r\n        \"sendToQueue\": \"true\",\r\n        \"retryNumber\": 1,\r\n        \"uploadFile\": \"testS3file\"\r\n    }",
    "inputDetails": {
        "__type": "com.amazonaws.swf.base.model#CloudWatchEventsExecutionDataDetails",
        "included": true
    },
    "name": "name",
    "output": "{\"statusCode\":200,\"body\":\"{\\\"input\\\": {\\\"sendToQueue\\\": \\\"true\\\", \\\"retryNumber\\\": 1, \\\"uploadFile\\\": \\\"testS3file\\\"}}\"}",
    "outputDetails": {
        "__type": "com.amazonaws.swf.base.model#CloudWatchEventsExecutionDataDetails",
        "included": true
    },
    "startDate": 1.618947563121E9,
    "stateMachineArn": "ARN",
    "status": "SUCCEEDED",
    "stopDate": 1.618947563572E9
}

I had this same question and asked some of the internal AWS folks and they said it isn't possible to change the output at this point.

The workaround, like you suggested, is API Gateway -> Lambda -> Step Function instead of API Gateway -> Step Function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM