Use path params in serverless framework 1.0

Marcel picture Marcel · Aug 23, 2016 · Viewed 8.7k times · Source

I want to use the path param /customer/{customerId} of a GET request in order to query a customer using AWS Lambda:

functions:
  createCustomer:
    handler: handler.createCustomer
    events:
    - http:
        path: customer
        method: post
  readCustomer:
    handler: handler.readCustomer
    events:
    - http:
        path: customer
        method: get

How do I have to define the path param in order to pass it to my AWS Lambda function using serverless framework 1.0?

Answer

Frank picture Frank · Mar 15, 2017

Define in serverless.yml

readCustomer:
  handler: handler.readCustomer
  events:
    - http:
        path: customer/{customerId}
        method: get

Access customerId in code

const customerId = event.pathParameters.customerId;