Reputation: 534
I'm trying to call a basic lambda from my API Gateway console. The lambda has an input taken in by the event called filterBy
.
I created a query string called filterBy
however, when I try to invoke the lambda I get the error:
{errorMessage: {'statusCode': 500, 'body': '{"msg": "KeyError(\'filterBy\')"}'}}
Presumably because the piece of code in my lambda
event['filterBy']
is not finding a filterBy in the event. What do I need to do so that I can get the filterBy in the event from the API Gateway console? I understand this is probably quite simple but I surprisingly cannot find anything about this so any help would be appreciated.
Upvotes: 0
Views: 1348
Reputation: 815
Based on the integration type, approach can be vary.
1. Lambda custom integrations
Looks like you are trying to use Lambda custom integrations. If that is the case you have to add a mapping template as below.
(under the Integration Request -> Mapping Templates --> Add mapping template
)
{
"filterBy": "$input.params('filterBy')"
}
Please refer this article or this video for more info.
2. Lambda proxy integrations
If you are using Lambda proxy integration (either as REST API or as HTTP APIs), then instead of event['filterBy']
, you have to access the queryStringParameters
first and then access the relevant query param.
event['queryStringParameters']['filterBy']
And another thing is: once you modify something in API GW, please make sure to deploy and wait some time before test. :)
Upvotes: 1