1

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'
        }
    }

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

If invoking your Lambda function from the command-line, another reason for event being empty could be a change between the v1 and v2 of AWS CLI. Compare:

Where in AWS CLI v1 you could do:

invoke
aws lambda invoke \
--function-name LambdaPhono \
--invocation-type Event \
--payload file://inputFile.txt \
outputfile.txt

In AWS CLI v2 you need to do:

invoke
aws lambda invoke \
--function-name LambdaPhono \
--cli-binary-format raw-in-base64-out \
--invocation-type Event \
--payload file://inputFile.txt \
outputfile.txt

Mind the new --cli-binary-format raw-in-base64-out option in v2.

This is documented here: https://docs.aws.amazon.com/cli/latest/userguide/cliv2-migration.html#cliv2-migration-binaryparam

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.