【问题标题】:Adding API to Usage Plan using Serverless Framework使用无服务器框架将 API 添加到使用计划
【发布时间】:2022-04-22 00:58:18
【问题描述】:

我的serverless.yaml文件如下:

service: aws-python

provider:
  name: aws
  runtime: python2.7
  stage: beta
  region: us-east-1

package:
  include:
    - deps
    - functions
    - lib

functions:
  hello:
    handler: functions/handler.function_handler
    events:
      - http:
          path: ta
          method: GET
      - http:
          path: ta
          method: POST

我想将此 API 添加到使用计划中。这是怎么做到的?

【问题讨论】:

  • 如果你要对帖子投反对票,你需要解释一下自己。
  • Serverless 默认不支持此功能,但您应该能够在 Serverless CloudFormation 模板中创建 UsagePlan 资源,或使用 AWS CLI 脚本创建 UsagePlan

标签: python amazon-web-services aws-api-gateway serverless-framework


【解决方案1】:

如 cmets 中所述,Serverless 默认不支持此功能。您应该考虑将适当的资源作为自定义资源添加到您的 CloudFormation 模板,或者使用 AWS CLI 或其他开发工具包创建它。

【讨论】:

    【解决方案2】:

    通过以下命令使用 AWS CLI

    aws apigateway update-usage-plan --usage-plan-id <PLAN_ID> --patch-operations op=add,path=/apiStages,value=<API_ID>:<API_STAGE>
    

    【讨论】:

      【解决方案3】:

      以上答案已过时。现在支持使用计划和 API 密钥。见这里:https://www.serverless.com/framework/docs/providers/aws/events/apigateway#setting-api-keys-for-your-rest-api

      这是上述文档中的示例:

      provider:
        apiGateway:
          apiKeys:
            - free:
                - myFreeKey
                - ${opt:stage}-myFreeKey
            - paid:
                - myPaidKey
                - ${opt:stage}-myPaidKey
          usagePlan:
            - free:
                quota:
                  limit: 5000
                  offset: 2
                  period: MONTH
                throttle:
                  burstLimit: 200
                  rateLimit: 100
            - paid:
                quota:
                  limit: 50000
                  offset: 1
                  period: MONTH
                throttle:
                  burstLimit: 2000
                  rateLimit: 1000
      

      【讨论】:

        猜你喜欢
        • 2021-11-25
        • 2017-02-12
        • 1970-01-01
        • 2019-01-27
        • 2017-12-03
        • 2020-05-27
        • 2017-09-30
        • 1970-01-01
        • 2019-12-26
        相关资源
        最近更新 更多