Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query params not propagated to lambda from api gateway integration #117

Open
azizmb opened this issue Dec 8, 2016 · 4 comments
Open

Query params not propagated to lambda from api gateway integration #117

azizmb opened this issue Dec 8, 2016 · 4 comments

Comments

@azizmb
Copy link

azizmb commented Dec 8, 2016

I'm trying to set up an apigateway <-> lambda integration, but am struggling with getting a query param passed to the lambda. From the docs and examples, I see I should have something like the following in my lambda:

apigateway:
  my-api:
    description: API for layer callbacks
    resources:
      /test:
        methods: [GET, POST]
        parameters:
          method.request.querystring.verification_challenge: True
        integration:
          lambda: myapp.helloworld
          parameters:
            integration.request.querystring.verification_challenge: method.request.querystring.verification_challenge

Yet, with this, the query string param (verification_challege) does not get propagated to the lambda, and events is an empty dict.

Am I doing something wrong?

Attached is a sample application to try this: urlparam.zip
After applying,

$ curl https://<gateway domain>/dev/test?verification_challenge=asdf
"{}"
@azizmb azizmb changed the title Query params not propagated to lambda Query params not propagated to lambda from api gateway integration Dec 8, 2016
@ahl
Copy link
Contributor

ahl commented Dec 16, 2016

I think--but I'm not completely sure--that the integration parameters work a little bit differently than you're expecting. I believe that integration parameters are intended to let you remap request parameters. What you need is a request_template to map the query string into the json body of the request. Try something like this:

apigateway:
  my-api:
    description: API for layer callbacks
    resources:
      /test:
        methods: [GET, POST]
        parameters:
          method.request.querystring.verification_challenge: True
        integration:
          lambda: myapp.helloworld
        request_templates:
          application/json: |
    #set($allParams = $input.params())
    {
      "body-json" : $input.json('$'),
      "params" : {
        #foreach($type in $allParams.keySet())
        #set($params = $allParams.get($type))
        "$type" : {
          #foreach($paramName in $params.keySet())
          "$paramName" : "$util.escapeJavaScript($params.get($paramName))"
          #if($foreach.hasNext),#end
          #end
        }
        #if($foreach.hasNext),#end
      #end
      },
      "context" : {
        "resource-path" : "$context.resourcePath",
        "http-method" : "$context.httpMethod"
      }
    }

When testing with curl remember to either specify a request for application/json since it uses application/x-www-form-urlencoded by default.

For another example check out: https://github.com/ahl/nojo/blob/master/gordon/settings.yml

As a side note, the integration parameter remapping seems at best misleading and at worst useless.

@astewart-twist
Copy link

So, is there no way to use query parameters with APIGateway <-> Lambda via Gordon?

@ahl
Copy link
Contributor

ahl commented May 9, 2017

What I described above is how you use query parameters.

@BradZzz
Copy link

BradZzz commented Oct 10, 2017

You have to map your query params to the message body in the message execution section of the apigateway as described here. Below is the exact template im using for my test endpoint.

#set($inputRoot = $input.path('$')) { "pi": "$input.params('pi')", "e": "$input.params('e')" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants