如何将路径参数添加到 AWS::Serverless::Function

How to add path parameter to AWS::Serverless::Function

我有一个生成 API 的 cloudformation 模板。我希望端点之一具有路径参数。但是,我不明白如何使用 AWS::Serverless::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

这会创建一个类似于 aws-domain-example.com/v1/items 的端点。这很好用。

不过,我想要aws-domain-example.com/v1/items/{item_id}

如何添加路径参数?

我认为模板应该如下所示。所以你可以访问它 event.pathParameters.itemCode

      Events:
        Get:
          Type: Api
          Properties:
            Path: /item/{itemCode}
            Method: get