8

Can we create a Rest URL like below in API Gateway?

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

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

mightymahesh
  • 303
  • 3
  • 14

4 Answers4

9

this is very late but I had the same issue and found the problem:

From AWS API Gateway Reference:

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

Amazon API Gateway does not support nested query parameters of the form: GET /team?user[id]=usrid on a method request. You could work around this limitation by passing an encoded map as a single parameter and serializing it as part of a mapping template or in your back-end integration.

So a fix you could use is restructuring your request such that:

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

Hope this helps!

Community
  • 1
  • 1
Rob Boykin
  • 99
  • 5
3

AWS API events have a "multiValueQueryStringParameters" field which can be used instead of "queryStringParameters". It will contain value arrays for all parameters:

idArray = event["multiValueQueryStringParameters"]["id"]

KenHuffman
  • 106
  • 1
  • 4
0

Try sending array with json syntax e.g.: /employees?ids=['1','2','3']

0

This could 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"
    }
  }
}
SLV
  • 331
  • 2
  • 4