Note: This is not a question an integration response that is a VTL template, gateway response is not a VTL template, per AWS docs.
How do I get access to the the incoming body to in a API Gateway BAD_REQUEST_BODY?
In the documentation for API Gateway responses it states that certain gatweay errors can return non-VTL templates but the gateway response can access $context
, $stageVariables
, and method.request.<x>
. But I can only get access to some of the $context variables.
I would like to access the incoming request body, just pull one property from the incoming request and return that property in the BAD_REQUEST_BODY response
I see more info in the API GW Logs which makes me assume this information is accessible:
Execution log for request xxxxx-2541-4e8e-8214-xxxx
Mon May 13 16:26:22 UTC 2024 : Starting execution for request: xxx-2541-4e8e-8214-xxxxx
Mon May 13 16:26:22 UTC 2024 : HTTP Method: PUT, Resource Path: /test-endpoint
Mon May 13 16:26:22 UTC 2024 : Method request path: {}
Mon May 13 16:26:22 UTC 2024 : Method request query string: {}
Mon May 13 16:26:22 UTC 2024 : Method request headers: {}
Mon May 13 16:26:22 UTC 2024 : Method request body before transformations: {
"pk": "COMP123",
"colB": "USA"
}
Mon May 13 16:26:22 UTC 2024 : Request body does not match model schema for content type application/json: [instance type (string) does not match any allowed primitive type (allowed: ["boolean"])]
Mon May 13 16:26:22 UTC 2024 : Gateway response type: BAD_REQUEST_BODY with status code: 400
Mon May 13 16:26:22 UTC 2024 : Gateway response body: {
"key": {
"colA": "<How do I access $input.body($.pk)>"
},
"rowAccepted": false,
"errors": [
"BAD_REQUEST_BODY",
"[instance type (string) does not match any allowed primitive type (allowed: ["boolean"])]",
""
],
,
}
Current Gateway Response template:
{
"key": {
"pk": "$context.requestOverride.path.body.pk"
},
"rowAccepted": false,
"errors": [
"$context.error.responseType",
"$context.error.validationErrorString",
"$context.integration.error"
]
}