Search code examples
pythonamazon-web-servicesaws-lambdacloud9-ide

Lambda event returns empty object


I need to access event["pathParameters"] but the event returns an empty object. I created the function with AWS Cloud9 IDE.

Here is my simple function:

def handler(event, context):
    return {
        'statusCode': 200,
        'body': json.dumps(event),
        'headers': {
            'Content-Type': 'application/json'
        }
    }

Solution

  • event is set by the payload you're invoking the lambda with.

    When you use API gateway, that payload includes the key pathParameters, but when you're testing using the lambda console you'll need to form the JSON yourself. The console does include an example of an API gateway proxy event in its templates section.

    For a more complete reference see: https://docs.aws.amazon.com/lambda/latest/dg/eventsources.html#eventsources-api-gateway-request