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

Urlencoded GET parameters #848

Closed
random1st opened this issue May 12, 2017 · 9 comments
Closed

Urlencoded GET parameters #848

random1st opened this issue May 12, 2017 · 9 comments
Labels

Comments

@random1st
Copy link

I have used Dynamic Rest library with additional filtering. If I use standard filter expression like as '/api/receipt-image/?filter{receipt}=1' I get empty response. It is properly works with '/api/receipt-image/?filter%7Breceipt%7D=1'. I think it concerned event's parsing.

@scoates
Copy link
Collaborator

scoates commented May 19, 2017

Hi there.
This is not a Zappa problem, but it seems to be a limitation of the API Gateway (similar to foo=1&foo=2 not working on APIGW).

Consider this Lambda function (no Zappa):

from __future__ import print_function

import json

print('Loading function')


def respond(err, res=None):
    return {
        'statusCode': '400' if err else '200',
        'body': err.message if err else json.dumps(res),
        'headers': {
            'Content-Type': 'application/json',
        },
    }


def lambda_handler(event, context):
    print("Received event: " + json.dumps(event, indent=2))
    
    return respond(None, event)

Wired this up to apigw and hit it with curl:

curl -s 'https://REDACTED.execute-api.us-east-1.amazonaws.com/prod/sc-test3?filter{receipt}=1' | python -mjson.tool

The relevant output is:

    "queryStringParameters": {
        "filterreceipt": "1"
    },

Unfortunately, I don't believe there's anything we can do to fix this in Zappa.

@Miserlou: I suggest close.

@scoates
Copy link
Collaborator

scoates commented May 19, 2017

Addendum: please ask AWS support to request a fix from the apigw team. If enough of us do this, it might work.

@random1st
Copy link
Author

You are not right. I fixed it when I work with API Gateway directly. I encode querystring with base64 in API Gateway templates mapping and decode when params received in lambda event. It works for me and i think no reason not to work for you

@scoates
Copy link
Collaborator

scoates commented Nov 26, 2017

Can you elaborate? How?

@random1st
Copy link
Author

This is part of my AG template

"resource_path" : "$context.resourcePath",
"http_method" : "$context.httpMethod",
"headers": {
    #foreach($param in $input.params().header.keySet())
    "$param": "$util.escapeJavaScript($input.params().header.get($param))" #if($foreach.hasNext),#end

    #end
  },
"query_params": {
    #foreach($param in $input.params().querystring.keySet())
    "$param": "$util.base64Encode($input.params().querystring.get($param))" #if($foreach.hasNext),#end

    #end
  },
"path_params": {
    #foreach($param in $input.params().path.keySet())
    "$param": "$util.escapeJavaScript($input.params().path.get($param))" #if($foreach.hasNext),#end

    #end
  }
}```


In lambda handler

if 'query_params' in event:
        event['query_params'] = {
            k: base64.b64decode(v).decode("utf-8")
            for k, v in event.get('query_params', {}).iteritems()
            }

@scoates
Copy link
Collaborator

scoates commented Feb 3, 2018

Hi. I finally had a chance to look into this today. Are you sure that Apache Velocity template turns ?filter{receipt}=1 into base64 encoding for the key name?

I couldn't get it to work directly with apigw+lambda with this template (there's a syntax error at the start of your example, but I think that's just missing a {). Looks like maybe you're only encoding/decoding the values, not the keys?

@scoates
Copy link
Collaborator

scoates commented Feb 3, 2018

Update: even a straight-up "sc_test" : "$input.params().querystring", in the Velocity template gives event.get('sc_test') == '{filterreceipt=1}' in raw (non-Zappa) lambda, for ?filter{receipt}=1.

Very interested in how you accomplished this, if it works for you. (-:

@scoates
Copy link
Collaborator

scoates commented Feb 23, 2018

Going to close this one. Please reopen if there is new information.

@scoates scoates closed this as completed Feb 23, 2018
@scoates
Copy link
Collaborator

scoates commented Oct 16, 2018

Related: the REQUEST type might allow us to do this. More info: in #1159.

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

No branches or pull requests

2 participants