Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass a querystring or route parameter to AWS Lambda from Amazon API Gateway

for instance if we want to use

GET /user?name=bob

or

GET /user/bob

How would you pass both of these examples as a parameter to the Lambda function?

I saw something about setting a "mapped from" in the documentation, but I can't find that setting in the API Gateway console.

  • method.request.path.parameter-name for a path parameter named parameter-name as defined in the Method Request page.
  • method.request.querystring.parameter-name for a query string parameter named parameter-name as defined in the Method Request page.

I don't see either of these options even though I defined a query string.

like image 280
MonkeyBonkey Avatar asked Jul 09 '15 23:07

MonkeyBonkey


1 Answers

As of September 2017, you no longer have to configure mappings to access the request body.

All you need to do is check, "Use Lambda Proxy integration", under Integration Request, under the resource.

enter image description here

You'll then be able to access query parameters, path parameters and headers like so

event['pathParameters']['param1'] event["queryStringParameters"]['queryparam1'] event['requestContext']['identity']['userAgent'] event['requestContext']['identity']['sourceIP'] 
like image 159
Jonathan Avatar answered Sep 30 '22 09:09

Jonathan