简体   繁体   English

使用无服务器框架将 API 添加到使用计划

[英]Adding API to Usage Plan using Serverless Framework

My serverless.yaml file is as follows:我的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

I want to add this API to a Usage Plan.我想将此 API 添加到使用计划中。 How is this done?这是怎么做到的?

As mentioned in comments, Serverless doesn't support this by default.正如评论中提到的,Serverless 默认不支持。 You should look to add the appropriate resources to your CloudFormation template as a custom resource or create it using the AWS CLI or another SDK.您应该考虑将适当的资源作为自定义资源添加到您的 CloudFormation 模板,或者使用 AWS CLI 或其他开发工具包创建它。

通过以下命令使用 AWS CLI

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

The above answers are outdated.以上答案已过时。 Usage plans and API keys are now supported.现在支持使用计划和 API 密钥。 See here: https://www.serverless.com/framework/docs/providers/aws/events/apigateway#setting-api-keys-for-your-rest-api请参阅此处: https://www.serverless.com/framework/docs/providers/aws/events/apigateway#setting-api-keys-for-your-rest-api

Here is the example from the above document:以下是上述文档中的示例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用无服务器框架验证 api - Validating api using serverless framework CloudFormation - 如何参考无服务器使用计划? - CloudFormation - How can I reference a serverless usage plan? 如何使用无服务器框架创建 API 的新版本? - How do you create a new version of an API using serverless framework? 如何使用 Serverless Framework 管理 Lambda 内部的 Aurora Serverless 数据 api 的 typeORM 连接 - How to manage typeORM connection of Aurora Serverless data api inside Lambda using Serverless Framework 如何使用无服务器框架为 API 网关设置描述? - How to set a description for an API Gateway using the Serverless Framework? 将使用计划附加到 API 密钥不适用于“createUsagePlanKey” - Attaching an usage plan to an API Key is not working with `createUsagePlanKey` 使用无服务器框架请求验证 - Request validation using serverless framework AWS - 无服务器离线框架上可用的 API 个密钥? - AWS - API keys available on the Serverless Offline framework? 无法将 AWS API 网关使用计划引用为 Terraform 中的数据源 - Unable to reference an AWS API Gateway Usage Plan as a data source in Terraform CORS 关于在无服务器框架中使用 REACT 应用程序的问题 - CORS question on using a REACT app with Serverless Framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM