I'm new to AWS and I've just successfully setup a Lambda function with RDS connection. Now I'd like to access my new function from outside through the API gateway and passing a few arguments like: "color" : "red"
https://my-api-id.execute-api.region-id.amazonaws.com/flowers?color=red
I've setup everything following the developer guide but unfortunately I'm not able to access the GET parameter in my Python Lambda function.
What I've done so far in my AWS API Gateway:
name: color
, mapped: method.request.querystring.color
I tried to access the color
parameter in the lambda handler but the event is always empty and I don't know where the parameter are supposed to be otherwise
def handler(event, context):
return event // {}
I think I'm not able to use the body mapping tamplates unless I do not have a request body using GET.
Does anybody know what I need to do in my Python Lambda function, in order to access my color
parameter?
A Python lambda function behaves like a normal function in regard to arguments. Therefore, a lambda parameter can be initialized with a default value: the parameter n takes the outer n as a default value.
Use Lambda Proxy as your integration request type.
And in your handler,
def handler(event, context):
return {
'statusCode': 200,
'body': json.dumps(event),
}
Your query parameters should be accessible as event['queryStringParameters']
.
Reference: Set up a Proxy Resource with the Lambda Proxy Integration
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With