1

我无法在SAM 项目requred query string params的文件中指定。template.yml到目前为止,我没有找到这样的方法,只发现我们可以通过event.queryStringParameters标头访问 lambda 函数中的查询字符串参数。

那么我应该检查 lambda 层是否需要参数吗?或者有没有办法在 API 层本身做到这一点。因为我知道在serverless框架中我们可以指定是否需要查询字符串参数,如下所示:

functions:
  create:
  handler: posts.create
  events:
    - http:
      path: posts
      method: get
      request:
        parameters:
          querystrings:
            type: true
4

2 回答 2

4

请在下面找到适合我的 template.yaml 片段。Ofc 你需要替换占位符。

MyFunction:
   Type: AWS::Serverless::Function 
   Properties:
        CodeUri: <path/to/your/lambda>
        Role: <arn of lambda role>
        Events:
            MyGetEvent:
                Type: Api 
                Properties:
                    Path: <my/api/path>
                    Method: get
                    RestApiId:
                        Ref: MyApi
                    RequestParameters:
                        - method.request.querystring.myqueryparam:
                             Required: true
于 2020-10-28T19:00:43.350 回答
1

您无需在 template.yml 中指定查询字符串参数。调用“http(s)://URL?key=value”之类的 API,然后通过 event.queryStringParameters 在 lambda 中解析它们,仅此而已。

于 2020-05-21T02:14:48.163 回答