- Newest
- Most votes
- Most comments
-
First, parse the entire response to get access to the 'output' field: #set($stepFunctionResponse = $util.parseJson($input.body))
-
Then, parse the 'output' field, which is itself a JSON string: #set($outputJson = $util.parseJson($stepFunctionResponse.output))
-
Now you can access the body: #set($body = $outputJson.body)
-
If you want to return just the body in your API response, you can do: $util.toJson($body)
This approach first parses the entire Step Functions response, then specifically parses the 'output' field which contains your desired data. After these steps, you should be able to access the body content correctly.
If you want to modify the response structure or include additional fields, you can create a new object and populate it with the data you need:
#set($response = {}) $response.put("statusCode", $outputJson.statusCode) $response.put("body", $body)
$util.toJson($response)
This will give you a properly formatted JSON response with the status code and body from the Step Functions output.
Remember to adjust your API Gateway method response and integration response settings to ensure the correct content type (application/json) is set and that the response is passed through correctly.
Sources
Set up an integration response in API Gateway - Amazon API Gateway
Create API Gateway REST APIs with Step Functions - AWS Step Functions
answered 2 years ago
I think the issue is with the input.path. Try input.json, like this: $util.parseJson($input.json('$.output')).
Relevant content
asked 4 years ago
