【问题标题】:How to add path parameter to AWS::Serverless::Function如何将路径参数添加到 AWS::Serverless::Function
【发布时间】:2020-06-09 13:48:24
【问题描述】:

我有一个生成 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}

如何添加路径参数?

【问题讨论】:

  • 在上面的模板中更改PathPath: /items/{item_id} 不起作用?

标签: amazon-web-services amazon-cloudformation aws-api-gateway aws-serverless


【解决方案1】:

我相信模板应该如下。所以你可以通过event.pathParameters.itemCode访问它

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

【讨论】:

    猜你喜欢
    • 2021-02-11
    • 1970-01-01
    • 2013-11-16
    • 2018-05-13
    • 2020-07-22
    • 2021-02-25
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    相关资源
    最近更新 更多