AWS API Gateway Integration Response Mapping Template using request body

0

I have an API Gateway resource setup with the below flow:

POST $request -> Method Request -> Integration Request -> Step Function
$response <- Method Response <- Integration Response

Currently, $response comes back as the response body from invoking the Step Function correctly. However, I want to know if there is a way I can use mapping templates to grab some values from the body of the request. For example, my request body looks something like this:

{
  "Value": {
    "Item1": "one",
    "Item2": "two"
  }
}

I would like to be able to grab the 2 properties under "Value" and return a response that looks something like this:

{
  "Item1": "one",
  "Item2": "two"
}

I have tried using the following mapping template:

{
  "Item1": $input.json('$.Value.Item1'),
  "Item2": $input.json('$.Value.Item2')
}

However, I have realised that the value of $input actually comes from the response of the Step Function (I had assumed it was the input to the entire resource).

Is there a way to access the request body in the response mapping template? The only alternative I can think of at this point is to add a Lambda Function between the API Gateway and Step Function to return the custom response after invoking the Step Function, but I would prefer to avoid this if possible.

1개 답변
0

Response mapping template can only map from the Integration Response to the Method Response.

Have you tried adding the input to the request as part of the payload that is passed onto the Step Function and have the Step Function return it back in the Integration Response? You should then be able to use the data from the incoming request in your mapping template, since it is now part of the integration response.

profile pictureAWS
전문가
답변함 2년 전
  • That is what I thought. Unfortunately, the Step Function is executed asynchronously, so I can't get a response back from the execution. I only get a JSON payload direct from the Step Function to say that execution has started (with the ARN of the SF). Unless there's another option that I'm missing?

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인