14

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:

  • Creating a resource "/flowers" and a GET method
  • GET -> Method Request -> URL Query String Parameters -> Added "color"
  • GET -> Integration Request -> Type: Lambda function
  • GET -> Integration Request -> URL Query String Parameters -> Added 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?

3

1 Answer 1

23

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

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.