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