Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass multi value query string parameter to lambda on api gateway?

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

like image 524
DevMops Avatar asked Apr 17 '26 13:04

DevMops


2 Answers

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.

like image 108
gdoumenc Avatar answered Apr 20 '26 09:04

gdoumenc


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.

like image 39
DevMops Avatar answered Apr 20 '26 09:04

DevMops



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!