'Adding API to Usage Plan using Serverless Framework
My serverless.yaml
file is as follows:
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. How is this done?
Solution 1:[1]
Used the AWS CLI with the following command
aws apigateway update-usage-plan --usage-plan-id <PLAN_ID> --patch-operations op=add,path=/apiStages,value=<API_ID>:<API_STAGE>
Solution 2:[2]
As mentioned in comments, Serverless doesn't support this by default. 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.
Solution 3:[3]
The above answers are outdated. Usage plans and API keys are now supported. See here: 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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jason Strimpel |
Solution 2 | Bob Kinney |
Solution 3 | Tim Ludwinski |