Reputation: 303
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
Upvotes: 8
Views: 7545
Reputation: 106
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"]
Upvotes: 3
Reputation: 331
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 protected]",
"contacts[home][twitter]": "@username"
}
// become:
event.params.querystring = {
"person": [{
"name": "Mark",
"age": 32
}, {
"name": "Luke",
"age": 26
}],
"contacts": {
"home": {
"phone": "+3333333333",
"email": "[email protected]",
"twitter": "@username"
}
}
}
Upvotes: 0
Reputation: 99
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!
Upvotes: 9
Reputation: 217
Try sending array with json syntax e.g.: /employees?ids=['1','2','3']
Upvotes: 0