AWS API Gateway, lambda function with path parameter in python?

318 Views Asked by At

Does someone have an example of an API Gateway lambda function that receives a path parameter, that is written in python? Every example I can find is written in javascript, and doesn't quite connect for me.

Here's what I mean: from my-template.yaml:

Events:
  Call:
    Type: Api
    Properties:
      Path: /blast-jobs/{id}
      Method: get

I'm not getting something named "id" in my event, what should I be expecting?

1

There are 1 best solutions below

2
On

The event your Lambda receives contains a field called pathParameters.

This python Lambda:

def lambda_handler(event, context):
    print(event['pathParameters'])

prints out:

{'id': '987654'}

when this URL is invoked

<gateway_invoke_url>/Prod/blast-jobs/987654