Passing array query parameters using API Gateway in lambda

Is it possible to create a Rest url like below in API Gateway?

[GET] / employee? id = 1 & id = 2 & id = 3 & id = 4

I cannot find a way to send an id array and get that array into a lambda function (python)

+3


source to share


3 answers


It's very late, but I had the same problem and found the problem:

From AWS API Server Link :

When the query parameter is a list type, its value must be a comma-separated string. For example, GET / restapis / restapi_id / deployments / deployment_id? Embed = apisummary, sdksummary.

Amazon API Gateway does not support nested form request parameters: GET / team? user [id] = usrid in method request. You can work around this limitation by passing the encoded map as the only parameter and serializing it as part of the mapping pattern or in your integration integration.



So the fix you can use is to restructure your query to:

[GET] /employees?id=1,2,3,4

Hope this helps!

+4


source


Try sending an array with json syntax like: /employees?ids=['1','2','3']



0


source


This can help in javascript

https://www.npmjs.com/package/amazon-api-gateway-querystring

var mapQueryString = require('amazon-api-gateway-querystring');
event.params.querystring = mapQueryString(event.params.querystring);

event.params.querystring = {
  "person[0][name]": "Mark",
  "person[0][age]": 32,
  "person[1][name]": "Luke",
  "person[1][age]": 26,
  "contacts[home][phone]": "+3333333333",
  "contacts[home][email]": "email@email.com",
  "contacts[home][twitter]": "@username"
}

// become: 

event.params.querystring = {
  "person": [{
    "name": "Mark",
    "age": 32
  }, {
    "name": "Luke",
    "age": 26
  }],
  "contacts": {
    "home": {
      "phone": "+3333333333",
      "email": "email@email.com",
      "twitter": "@username"
    }
  }
}

      

0


source







All Articles