By using AWS re:Post, you agree to the AWS re:Post Terms of Use

Map step function response to the response body of an HTTP API Gateway V2 integration

0

Ive got an HTTP API Gateway V2 invoking a synchronous Express Step Function thru AWS Service Integration via StepFunctions-StartSyncExecution. My problem is that the response from the Step Function seems to always be in the form of:

{
   "billingDetails": { 
      "billedDurationInMilliseconds": number,
      "billedMemoryUsedInMB": number
   },
   "cause": "string",
   "error": "string",
   "executionArn": "string",
   "input": "string",
   "inputDetails": { 
      "included": boolean
   },
   "name": "string",
   "output": "string",
   "outputDetails": { 
      "included": boolean
   },
   "startDate": number,
   "stateMachineArn": "string",
   "status": "string",
   "stopDate": number,
   "traceHeader": "string"
}

And that gets passed as the response to the client calling the API Gateway. I just want the value of the output field (as JSON) from that big JSON blob. As far as I can tell there doesn’t seem to be a way with HTTP API Gateway V2 to transform the integration response into the clean final response. As far as I can tell, parameter mapping will only work for headers, I can’t see how to rewrite the body. I can get the value in Integrations->parameter mapping but there doesn’t seem to be a way to overwrite the body. Only header.* The old v1 REST API gateway had mapping templates, but I can’t find anything like that for V2

Is there a way to do this that I'm missing?

3 Answers
1
Accepted Answer

Hi,

Unfortunately it is not possible to receive just the value of the output field from the StepFunctions execution, since it is the expected response format of the StartSyncExecution API operation. As you say, you could filter it using the integration response, but this is just supported on the REST API.

Finally, note that both REST APIs and HTTP APIs are valid RESTful API products, and you should chose depending on your use case needs.

profile picture
EXPERT
answered a year ago
profile picture
EXPERT
reviewed 7 months ago
profile picture
EXPERT
reviewed 7 months ago
  • This is an extreme bummer. I hope aws folks are working on a way to make it easy to have API Gateway more seamlessly call Step Functions where a proper response can be had from the Step Function. For now we have to add a Lambda just to act like a proxy.

    And we just realized that the proxy lambda has to keep running (and adding cost) so it can send the response back to the API Gateway

0

Should it be possible to do this with the OpenAPI x-amazon-apigateway-integration and the v2 API HTTP Gateway as per the article How to Build Lightning Fast APIs with AWS Step Functions? It's not clear to me if they are using the v2 API Gateway or not. I might try this when I get a chance.

profile picture
answered a year ago
  • Hi,

    They are using a mapping template (a script expressed in Apache Velocity Template Language) to modify the request and response body, but that is only supported on REST API. HTTP APIs just allows to modify headers or the status code of a response.

0

There is no way to do payload transformation in HTTP API (v2), only in REST API (v1).

profile pictureAWS
EXPERT
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions