【问题标题】:Defining URL Query String Parameters in AWS::Serverless::Api SAM template在 AWS::Serverless::Api SAM 模板中定义 URL 查询字符串参数
【发布时间】:2021-03-03 18:39:29
【问题描述】:

如何在 SAM 模板中定义和验证 AWS::Serverless::Api 的 URL 查询字符串参数?

文档https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-api.html中似乎没有提到它们

为了清楚起见,这就是我要说的

【问题讨论】:

  • 请在您的问题中添加您的模板 yaml/json

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


【解决方案1】:

URL 查询字符串参数是在 AWS::Serverless::Function 中定义的,而不是使用 RequestParameters 属性的 AWS::Serverless::Api。

例如,将mail、name、phone 定义为 URL 查询字符串参数,您可以执行以下操作:

Events:
  ApiEvent:
  Type: Api
  Properties:
    Path: /path
    Method: get
    RequestParameters:
      - method.request.querystring.mail:
          Required: true
          Caching: true
      - method.request.querystring.name:
          Required: true
          Caching: true
      - method.request.querystring.phone:
          Required: false
          Caching: false

您还可以使用以下方法定义 HTTP 请求标头:

method.request.header.{{header_name}}
// For example: method.request.header.Authorization

我希望这会有所帮助。

【讨论】:

    【解决方案2】:

    我认为您的响应是在另一个资源中,AWS::ApiGateway::Method。

    查看文档(搜索请求参数):

    API Gateway 接受的请求参数。将请求参数指定为键值对(字符串到布尔映射),源作为键,布尔值作为值。布尔值指定是否需要参数。源必须与格式 method.request.location.name 匹配,其中位置是查询字符串、路径或标头,名称是有效的唯一参数名称。

    https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-method.html#cfn-apigateway-method-requestparameters

    【讨论】:

      猜你喜欢
      • 2020-09-01
      • 1970-01-01
      • 2019-05-22
      • 2020-01-11
      • 2021-04-19
      • 1970-01-01
      • 1970-01-01
      • 2016-09-14
      • 2018-04-15
      相关资源
      最近更新 更多