How to get Resource Path on AWS API Gateway?

Viewed 15

I'm working with a AWS API Gateway that receives a {name} as prints out "Hello {name}" but I'm unable to get this trivial task right.

Any pointers what I could be doing wrong? How the can I get the {name} from the URL?

API Gateway: https://xxxxxx.execute-api.eu-west-1.amazonaws.com/dev/John

Python AWS Lamba code:

def lambda_handler(event, context):

    name = event["requestContext"]["resourcePath"]
    response = "Hello " + name
    
    return {
        'statusCode': 200,
        'body': response
    }

The expected output:

{
    "statusCode": 200,
    "body": "Hello John"
}
1 Answers

Use a proper mapping template on Gateway side. It cannot map whatever you want automatically, you need to configure what you expect there.

Related