Reputation: 96594
My lambda can use events["zip_code"]
when testing it in the management console and configuring the test event to have that.
How can I configure my APIgateway to pass zip_code ?
I've tried hundreds of different approaches over several hours. this should take about 30 seconds to figure out!
Current (stripped down) attempt:
I create a lambda. It can refer to event[zip_code"]
no problem. I create an API Gateway that points to it and I can call it. However every attempt I make to refer to the query string parameter in the lambda has failed.
I have tried:
event["zip_code"]
event["query_parameters"]["zip_code"]
event["queryStringParameters"]["zip_code"]
but they all give nil.
I've tried publishing my lambda (probably needed) and I've tried deploying my API to a particular stage, 'DEV' but neither seemed to help.
Upvotes: 3
Views: 5564
Reputation: 4002
You should be able to access query string parameters in Lambda using event["queryStringParameters"]["zip_code"]
as long as Use Lambda Proxy integration
is checked. If not, then you will need to set up custom mapping. In most of the use cases, proxy integration is the recommended option.
In Lambda proxy integration, when a client submits an API request, API Gateway passes to the integrated Lambda function the raw request as-is, except that the order of the request parameters is not preserved. This request data includes the request headers, query string parameters, URL path variables, payload, and API configuration data
Non proxy integration requires custom mapping.
In Lambda non-proxy integration, in addition to the proxy integration setup steps, you also specify how the incoming request data is mapped to the integration request and how the resulting integration response data is mapped to the method response
Upvotes: 5