Aws-sam-cli: queryStringParams returns list of Strings

Created on 11 May 2018  路  15Comments  路  Source: aws/aws-sam-cli

Description:
We just upgraded to SAM CLI 0.3.0 and noticed a change with queryStringParams where the query parameter is mapping to an array of a strings instead of a string. For example:

0.2.11 mapping: {"name":"jason"}

0.3.0 mapping: {'name': [u'jason']}.

We are using aws-serverless-java-container-jersey from https://github.com/awslabs/aws-serverless-java-container and it seems to break when trying to map the query parameter to a string when our endpoint is defined as follows:
public Response getHelloWorld(@QueryParam("name") String name)

We are not sure if SAM CLI is supposed to return a list of strings for query parameters or just a single string? Looking at the tests it seems that the expected behavior would be that each query parameter maps to a string and not a list of strings. test_api_event() in test_events.py has an expected_event where: 'queryStringParameters': {'foo': 'bar'}

Steps to reproduce the issue:

  1. Create a proxy integration lambda that prints out the inputStream
  2. Call the new API endpoint with a query parameter and a value

Observed result:
The query parameter is mapped to a list containing the value given

Output of sam --version:
SAM CLI, version 0.3.0

arelocastart-api priorit1-critical stagaccepted typbug typregression

Most helpful comment

Fix is out for review. Updating labels.

All 15 comments

On a side note, looking at generate_api_event() in event.py, query_params is defined as follows:

query_params = {
        "foo": "bar"
    }

However, it seems that the query_string_params that get passed into ApiGatewayLambdaEvent is of type ImmutableMultiDict. generate_api_event() is called in test_api_event() in test_events.py.

I am also having this issue. It is breaking existing unit tests.

Details:
Our live lambda functions are still behaving as expected:
"queryStringParameters": { "var": "val" },
but the same event in sam local is coming through as
"queryStringParameters": {"var": ["val"]}

python 2.7. Just upgraded to aws-sam-cli-0.3.0 today. Is this a game breaking lambda change that is on its way? or just a aws-sam issue?

This update broke my entire app. All the queryStringParameters are getting mapped to list of strings instead of being a string.

Working on a patch now. Will update when I have a PR out for this. Appologizes on the regression.

Seems like APIGW has non standard behavior with query strings.

Request with /id/blah?p=1,p=2 shows 'queryStringParameters': {'p': '2'} in the event json.
Request with /id/blah?p=[1,2,3] shows 'queryStringParameters': {'p': '[1,2,3]'} in the event json.
Request with /id/blah?p=blah shows 'queryStringParameters': {'p': 'blah'} in the event json.

So what needs to happen:
Last query string always wins if you pass query params like ?p=1,p=2
The query string will always be a string

Need to work out how Flask returns data back in different cases and map this to what APIGW is doing.

Fix is out for review. Updating labels.

I just want to add that this completely breaks dotnetcore. Passing any query string parameter at all results in an exception while invoking the handler:

Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing value: [. Path 'queryStringParameters...

I just tested the fix from @jfuss and it appears to be working so far.

@mrchops1024 The best thing I can suggest is installing SAM CLI from source with my patch until we can get that PR merged and a release out. Sorry for the troubles this causes.

@jfuss That's exactly what I did and so far there are no issues. Thanks.

@jfuss I also encountered this issue after upgrading to 0.3.0. Glad to see there's an open PR that addresses it. Any ETA on when the PR will be merged and a new release cut with the fix? Thanks!

@jonpierce I do not have an ETA yet. Going to poke some folks today in hopes to at least get it merged. I don't expect us to do a release right after that is merged though. There are a couple other regressions/bugs we need to fix and I think getting those into one release is best.

We are still working on some of these process related things (cadence/criteria for a release is one of them). Once I have some clarity on that, I will update this issue so folks can at least understand when it will happen. Hopefully that helps.

@jfuss Cool, no worries. I've installed your branch locally and can just use that until then. Thanks.

As a heads-up, this bug also completely breaks golang lambda functions. Trying to pass any query parameter results in the following error:

{
  "errorMessage": "json: cannot unmarshal array into Go struct field APIGatewayProxyRequest.queryStringParameters of type string",
  "errorType": "UnmarshalTypeError"
}

I can confirm that @jfuss patch fixes the problem. Would love to get an ETA on release...

This was merged into develop. Putting into stage/accepted until a release is cut.

This was released in v0.4.0

Closing.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nicosuave picture nicosuave  路  44Comments

chrisfosterelli picture chrisfosterelli  路  31Comments

charsleysa picture charsleysa  路  33Comments

dinvlad picture dinvlad  路  27Comments

kyeljmd picture kyeljmd  路  31Comments