3

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

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

Keep in mind that the version 2.0 lambda event replaces multiValueQueryStringParameters with queryStringParameters separated via comma.

Source: https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.