6

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?

RainSear
  • 629
  • 1
  • 8
  • 13
  • Can you post some of your code? Have you tested your API with the same data your sending with 'curl -d etc.'? – JohnAllen Jan 07 '16 at 07:11
  • If you're passing the data correctly, you should be able to access the data in lambda 'event' object that is passed to your lambda handler. You can try logging the contents of the event object in your handler. – JohnAllen Jan 07 '16 at 07:13

3 Answers3

3

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

Community
  • 1
  • 1
Ryan
  • 5,845
  • 32
  • 27
0

In order to send HTTP parameters to a lambda function, they need to be sent in the request body via a mapping template.

See this blog post for a simple example of how to do this.

RyanG
  • 3,973
  • 25
  • 19
0

This is another way to do it:

  1. Open API Gateway, select your endpoint and click on Resources

  2. Select Method Request in the settings

    enter image description here

  3. Under the URL Query String Parameters, you can add query string.

    enter image description here

As an example, in my Python lambda function, I can retrieve the query parameter just with the following:

def endpoint(event, context):
    my_parameter = event["queryStringParameters"]
Yuchen
  • 30,852
  • 26
  • 164
  • 234