I'm Getting an error_message:“Key error” when invoking a lambda using boto3.client.invoke

788 views Asked by At

I'm getting a Key error when invoking a lambda that is actually an API handler lambda. I invoke that specific route using the following syntax

invoke_payload = {
    'path': '/3d/terrain/{item_id}/{proxy+}',
    'httpMethod': 'GET',
    'headers': {'Accept':'application/octet-stream'},
    'multiValueHeaders': {},
    'queryStringParameters': {'access_token':jwt_token},
    'multiValueQueryStringParameters': None,
    'pathParameters': {'dataset_id': dataset_id,'proxy':proxy_path},
    'stageVariables': None,
    'requestContext': {
        'path': '/3d/terrain/{item_id}/{proxy+}',
        'resourcePath': '/3d/terrain/{item_id}/{proxy+}',
        'httpMethod': 'GET',
    },
    'body': None,
}


#syncronous call
response = client.invoke(FunctionName=arn,
                         InvocationType='RequestResponse',
                         Payload=json.dumps(invoke_payload))

result = json.loads(response.get('Payload').read())
return result

What could it be. I passed all the required pathParameters and i think the token should not be a problem.

When i make the get request in Postman i get the following:

 {
"errorMessage": "'item_id'",
"errorType": "KeyError",
"stackTrace": [
    "  File \"/var/task/chalice/app.py\", line 1040, in __call__\n    for name in route_entry.view_args}\n",
    "  File \"/var/task/chalice/app.py\", line 1040, in <dictcomp>\n    for name in route_entry.view_args}\n"
]
1

There are 1 answers

0
f7o On

Inside your path you are using the parameter item_id. But you do not path a value for it:

'pathParameters': {'dataset_id': dataset_id,'proxy':proxy_path}

Therefore you get a KeyError while reading the value for the parameter item_id