Skip to content

Local API Gateway Event should always contain PathParameters, etc - #220

Merged
PaulMaddox merged 2 commits into
aws:developfrom
djn658:event-object-omitempty-issue
Dec 7, 2017
Merged

PaulMaddox merged 2 commits into
aws:developfrom
djn658:event-object-omitempty-issue

Conversation

@djn658

@djn658 djn658 commented Dec 6, 2017

Copy link
Copy Markdown
Contributor

Currently Local API Gateway passes Event object that will crash Lambda Function. The Local API Gateway passes Event only with properties that has been declared by the runtime. This is not consistent with the behavior of the actual AWS API Gateway, which includes every property in the event.

To produce the error, please follow the following steps.

  1. Start with the sample Python project:
    https://github.com/awslabs/aws-sam-local/tree/develop/samples/python-with-packages

  2. Append the following code at the end of the lambda_sandbox_down_handler

    return {
        'statusCode': 200,
        'headers': {'Content-Type': 'application/json'},
        'body': json.dumps({'params': event['queryStringParameters']})
    }
  1. Run:
    $ aws-sam-local local start-api

  2. Go to the URL: http://127.0.0.1:3000, and you should be able to see the Internal Error message.

  3. Go back to terminal console and you can notice that the error is bought up by Python KeyError, since there is no queryStringParameters in event.

This issue should be fixed since the actual AWS API Gateway passes Event object with every key in it to Lambda Function, values to keys might be null while the keys always exist. Therefore I deleted omitempty argument for every property declaration in type Event struct, which fixed the issue.

I will appreciate it if you could take some time looking into this issue.

@PaulMaddox
PaulMaddox merged commit f80c385 into aws:develop Dec 7, 2017
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

Successfully merging this pull request may close these issues.

2 participants