I am having difficulty getting http method used in a call to aws lambda via api gateway. I created a REST api in api gateway, which makes a call to a lambda function. In the lambda function I want to have two functions, one for POST requests and one for GET requests. I am unable to get the method from event. In other threads answers are usually for javascript or java only.
I run the following curl command from my terminal:
curl "https://myurl/endpoint"
I also try to send a GET request via advanced rest client.
Here's what I'm trying to do:
def lambda_handler(event, context):
method = event['httpMethod']
if method == "GET":
return get_function()
if method == "POST":
return post_function()
Running the above code results in a keyError
.
I have tried this as well:
method = event['requestContext']['http']['method']
I tried printing out the event itself like this method = event
. All I get from this is {}
, both in the response and in cloudwatch.
How can I read the http method in a request