Adding API to Usage Plan

My serverless.yaml file is as follows:

service: TALib

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

package:
  include:
    - deps
    - functions
    - lib

functions:
  talib:
    handler: functions/handler.ta_lib_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?

As far as I can see, Usage Plans aren’t yet supported by CloudFormation, so there’s no way (that I know of) to do this in Serverless right now.

They are now: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-usageplan.html

2 Likes

Thank you - but can this be defined in the serverless.yml file? I have two different API keys that are associated with different usage plans (one for testing and another for our customer) - but all I see in the example (with no way to associate them is:
apiKeys: # List of API keys to be used by your service API Gateway REST API
- myFirstKey
- ${opt:stage}-myFirstKey
- ${env:MY_API_KEY} # you can hide it in a serverless variable
usagePlan: # Optional usage plan configuration
quota:
limit: 5000
offset: 2
period: MONTH
throttle:
burstLimit: 200
rateLimit: 100

1 Like

Did you find a solution, is it possible now to add an API to an existing Usage Plan?

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>