serverless-apigateway-route-settings

1.1.0 • Public • Published

serverless-apigateway-route-settings

serverless CircleCI npm contributions welcome

About

A Serverless Framework Plugin which helps you configure route specific variables, such as throttling rate limits, detailed metrics etc (see CloudFormation RouteSettings) for Api Gateway v2 (HTTP). Also allows defaults to be set in the custom attribute of your serverless.yml.

Supported RouteSettings

ApiGateway v2 seems to only accept the following RouteSettings for Api Gateway v2 (HTTP):

  • ThrottlingBurstLimit
  • ThrottlingRateLimit
  • DetailedMetricsEnabled

Get Started

npm install serverless-apigateway-route-settings

or

yarn add serverless-apigateway-route-settings

Edit your serverless.yml to use this plugin:

plugins:
  - serverless-apigateway-route-settings

Next, edit your serverless.yml for DefaultRouteSettings. What you enter here will be the default for each route in the stage.

custom:
  routeSettings:
    burstLimit: 200
    rateLimit: 400
    detailedMetricsEnabled: true

You can override the default route settings/account defaults by configuring at the route level. for example:

functions:
  hello:
    handler: src/throttle_me.handler
    events:
      - httpApi:
          path: /hello
          method: GET
          routeSettings:
            rateLimit: 10
            burstLimit: 5
            detailedMetricsEnabled: false

Caveats

  • Currently, if we are to deploy with default route settings specified, then remove them, they will persist, you MUST specify new default route settings. I aim to fix this in an update, will default to account levels.
  • Doesn't work with pre existing API Gateways, eg if they are existing and we simply add routes in the serverless.yml. It is possible to add this plugin to an existing api gateway which is handled by serverless however.

Example serverless.yml

service: example

frameworkVersion: '2'

plugins:
  - serverless-apigateway-route-settings

custom: 
  routeSettings:
    detailedMetricsEnabled: true
    rateLimit: 200
    burstLimit: 30

provider:
  name: aws
  runtime: nodejs12.x

functions:
  # Inherits the default route settings.
  hello:
    handler: src/helloWorld.handler
    events:
      - httpApi:
          path: /hello
          method: GET

  # Overrides the default throttle rate limits.
  lowerRateLimit:
    handler: src/lowerRateLimit.handler
    events:
      - httpApi:
          path: /throttle
          method: GET
          routeSettings:
            rateLimit: 10
            burstLimit: 3

What will be added to your CloudFormation template?

  • DefaultRouteSettings will be added to your Stage.
  • RouteSettings will be added to your Stage.
  • The DependsOn attribute is edited for your Stage. We simply add any Route's with configured RouteSettings, to ensure the creation of the Routes before the Stage. Otherwise CloudFormation will error (as it tries to edit the RouteSettings for a Route that doesn't exist yet).

Issues

If you encounter any bugs, please let me know here, and I will aim to fix them soon 🙂. Contributions are welcome, feel free to make a pull request into the develop branch.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.1.0136latest

Version History

VersionDownloads (Last 7 Days)Published
1.1.0136
1.0.00
0.0.60
0.0.50
0.0.40
0.0.31
0.0.20
0.0.10

Package Sidebar

Install

npm i serverless-apigateway-route-settings

Weekly Downloads

137

Version

1.1.0

License

ISC

Unpacked Size

17.6 kB

Total Files

8

Last publish

Collaborators

  • talbotp