jorgebastida/gordon

Query params not propagated to lambda from api gateway integration

azizmb opened this issue · 4 comments

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
"{}"
ahl commented

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.

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

ahl commented

What I described above is how you use query parameters.

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')" }