AWS API Gateway: How to configure request parameters when configured in a mapping template?

I cannot figure out how to create optional query string parameters using the mapping pattern in my resource integration request.

My template looks like this:

{ "limit": "$input.params('limit')", "post_date":"$input.params('post_date')" } 

I would like "limit" and "post_date" to be optional. This template creates a query that looks like when these parameters are not provided:

 /myresource?limit=undefined& 

When I expect:

  /myresource 

Docs don't seem to cover this. I found some sample templates in the documentation that use bash syntax to provide conditional functionality. I tried to test the following, but it will not be tested in the AWS console:

  #set($limit = $input.path('limit')) { #if($limit)"limit": "$input.params('limit')",#end } 

Am I on the right track?

Thanks!

+7
amazon-web-services aws-lambda aws-api-gateway
source share
1 answer

Yes, you absolutely can do it in Api Gateway; although this does not seem to be documented!

In your question, you mentioned that this is a parameter; but you used input.path, which usually refers to an element in the body of a POST request. The following should work:

 #set($limit = $input.params('limit')) { #if($limit && $limit.length() != 0) "limit": "$input.params('limit')" #end } 

Regarding the documentation, I found that the next page from AWS is actually very useful. However, he hid in the section on fictitious ends:

http://docs.aws.amazon.com/apigateway/latest/developerguide/how-to-mock-integration.html

+3
source share

All Articles