【问题标题】:Enable API key only for some functions from yml仅为 yml 中的某些函数启用 API 密钥
【发布时间】:2022-07-11 22:51:43
【问题描述】:
Function_Name:
  handler: function path
  events:
    - http:
        path: path/{id}
        method: get

我想添加该功能所需的apikey,我该怎么做?我不想从 aws 手动制作它。谢谢!

【问题讨论】:

    标签: node.js amazon-web-services aws-api-gateway serverless


    【解决方案1】:

    无服务器框架可以选择在serverless.yml 的提供程序部分下添加apiKeys。在下面找到示例代码供您参考。

    service: demo-api-key
    provider:
      name: aws
      runtime: nodejs12.x
      apiKeys:
        - "demo-apikey"
    functions:
      hello:
        handler: handler.hello
        events:
          - http:
              path: hello
              method: get
      message:
        handler: private.message
        events:
          - http:
              path: message
              method: get
              private: true
    

    或者查看此plugin 以获取替代方式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-15
      • 2020-08-17
      • 2023-03-07
      • 1970-01-01
      • 2018-01-06
      • 1970-01-01
      相关资源
      最近更新 更多