Skip to content

Accessing Lambda Python event - ERROR

0

In a Lambda Python function, I desire to get 3 data items from the lambda_handler event. Previously & recently this syntax worked: param = event.get('queryStringParameters') myUsername = param['Username']

Now in a new function, it has a bad error. I never get past the 1st item of data. I have set the test event to: { "Username" : "Priscilla", }

The error is: { "errorMessage": "'NoneType' object is not subscriptable", "errorType": "TypeError", "requestId": "fd866aa9-d83a-42f2-8d91-265f10814f43", "stackTrace": [ " File "/var/task/lambda_function.py", line 35, in lambda_handler\n myUsername = param['Username']\n" ] }

Any help would be appreciated.

asked 2 years ago720 views
2 Answers
0

Thank you - worked perfectly. Appreciated!

answered 2 years ago
  • Could you accept the answer as valid to reward those who helped you and continue to support others in need?

0

Hello.

When you issue a test event, the Lambda function's "event" will contain the json passed in the test event.
In other words, in this case, the json "{ "Username" : "Priscilla"}" is passed as is to the event, so "queryStringParameters" is None.
The cause of the error is that "queryStringParameters" is not included in the test event json.
So, I think it will work if you change the json used in the test event as follows.

{
    "queryStringParameters": 
    { 
        "Username" : "Priscilla"
    }
}
EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
AWS
EXPERT
reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.