[英]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.