I have an API deployed to REST API gateway.
My endpoint is https://<gateway-id>.execute-api.<region>.amazonaws.com/<stage>/items?pageSize=10
. This endpoint is integrated directly to DynamoDB using the Integration. I want to set a limit to the maximum value that can be passed as the query parameter, eg. 100. Any value beyond 100 should return a 400 – Bad request.
How to do this without having to use any other integration?
We tried to validate query param pageSize in request mapping template in VTL. That doesn’t seem to work as expected.
#if($input.params('pageSize') && $input.params('pageSize').toInt() > 100)
{
"statusCode": 400,
"error": "Bad Request",
"message": "Size parameter exceeds the maximum allowed value of 100"
}
#else
{
"TableName": "DDBTable",
"IndexName": "idx_name",
"Limit": $input.params('pageSize'),
"KeyConditionExpression": "GSI1PK = :v1",
"ExpressionAttributeValues": {
":v1": {"S": "1"}
},
"ReturnConsumedCapacity": "TOTAL",
"ScanIndexForward": false
}
#end