I'm using aws integration api gateway with lambda and i have data mapping template. The url with query is like
https://example.com/query?value1=val1&value1=val2&value1=val3
I'm trying to pass all those params to lambda, but have no luck - only last value is passed. Here is part of data mapping template.
"queryStringParameters": {
#foreach($queryParam in $input.params().querystring.keySet())
"$queryParam": "$util.escapeJavaScript($input.params().querystring.get($queryParam))" #if($foreach.hasNext),#end
#end
},
I know that there is multivaluequerystringparameters in aws proxy integration but had no luck finding them using data mapping template. Here is test results:
Method request query string: {value1=[val1,val2,val3]}
Endpoint request body after transformations: "queryStringParameters": {"value1": "val3"}
Tried to iterate through that parameter like in VTL using #foreach but had no luck with that too
After a lot of doc search and tries, I simply write this in the mapping template (lucky...) :
"multiValueQueryStringParameters": {
#foreach($key in $method.request.multivaluequerystring.keySet())
"$key" : [
#foreach($val in $method.request.multivaluequerystring.get($key))
"$val"#if($foreach.hasNext),#end
#end
]#if($foreach.hasNext),#end
#end
},
No need to define any query parameter name in method and integration part.
So... i had two ways, send my param as
&value1=[1,2,3]
or use aws_proxy and access this value1 from event
multiValueQueryStringParameters
I choosed the last one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With