2

I have a cloudformation template that generates an API. I want one of the endpoints to have a path parameter. However, I don't understand how I can achieve this with AWS::Serverless::Function. Here is my current function:

GetItems:
  Type: AWS::Serverless::Function
  Properties:
    Handler: api/items/get.handler
    Timeout: 29
    CodeUri: .
    Events:
      Get:
        Type: Api
        Properties:
          Method: get
          Path: /items
          RestApiId: !Ref MyAPI

This creates an endpoint like aws-domain-example.com/v1/items. This works just fine.

However, I want aws-domain-example.com/v1/items/{item_id}

How can I add a path parameter?

Gary Holiday
  • 3,297
  • 3
  • 31
  • 72

1 Answers1

6

I believe template should be as below. so you can access it as event.pathParameters.itemCode

      Events:
        Get:
          Type: Api
          Properties:
            Path: /item/{itemCode}
            Method: get
Amit Naik
  • 983
  • 1
  • 5
  • 16