Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass GET parameters to my AWS Lambda function when using an HTTP endpoint?

I followed the example from here to set up a sample AWS Lambda function: http://docs.aws.amazon.com/lambda/latest/dg/get-started-step4-optional.html.

Then, I created an HTTP GET endpoint via AWS API Gateway. I can access the endpoint but I don't know how to pass that int myCount as a parameter.

I tried ?myCount=3 as a GET parameter but that didn't work.

Any help?

like image 684
RainSear Avatar asked Jan 07 '16 03:01

RainSear


People also ask

Can you pass parameters to Lambda function?

Short description. 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 do you pass query parameters to Lambda?

To pass Api Gateway Querystring parameters to a lambda function, using non-proxy integration, you have to: Open the AWS Api Gateway console and click on your API's name. In the Resources tab, click on the specific HTTP method. Click on Method Request and expand the URL Query String Parameters section.

Does AWS Lambda use HTTP?

A Lambda integration maps a path and HTTP method combination to a Lambda function. You can configure API Gateway to pass the body of the HTTP request as-is (custom integration), or to encapsulate the request body in a document that includes all of the request information including headers, resource, path, and method.


1 Answers

You need to setup a mapping template in API Gateway. If you know the name of your parameters ahead of time your template could look like this:

{
  "myCount": "$input.params('myCount')",
  "myUserId": "$input.params('myUserId')"
}

Where each $input.params('...') will get evaluated and the value in your query string will be put in its place when the event is passed to Lambda.

This is pretty much a duplicate of passing query params for aws lambda function

like image 183
Ryan Avatar answered Nov 15 '22 09:11

Ryan