Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing array query parameters with API Gateway to lambda

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

like image 730
mightymahesh Avatar asked Apr 13 '17 21:04

mightymahesh


People also ask

How do I integrate Lambda with API gateway?

Step 1: Open API Gateway Management Console and choose the API. Step 2: Choose the resources. Choose the configured HTTP method. Step 3: Choose the Integration Request. Step 4: Select HTTP or Lambda as integration type.

How do I pass a query parameter to a lambda function?

To configure a REST API to pass query string parameters to a backend Lambda function, use a Lambda custom integration. To pass query string parameters to an HTTP endpoint, use an HTTP custom integration. Important: Make sure that the input data is supplied as the integration request payload.

How to accept array as the query parameter in API gateway?

The guide demonstrates how to accept the array as the query parameter in API Gateway proxy and non-proxy Lambda integrations In the non-proxy lambda integration, it is required to map the query parameter in the request mapping template to the lambda handler model property. Suppose our DTO has form of

How can I Pass query string parameters to a backend AWS Lambda?

I need my Amazon API Gateway REST API to pass query string parameters to a backend AWS Lambda function and an HTTP endpoint. How can I do that? To configure a REST API to pass query string parameters to a backend Lambda function, use a Lambda custom integration. To pass query string parameters to an HTTP endpoint, use an HTTP custom integration.


2 Answers

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"]

like image 44
KenHuffman Avatar answered Sep 20 '22 23:09

KenHuffman


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!

like image 143
Rob Boykin Avatar answered Sep 20 '22 23:09

Rob Boykin