JSPM

serverless-apigateway-route-settings

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 293
  • Score
    100M100P100Q98161F
  • License ISC

A Serverless Framework Plugin for configuring Route Settings for Api Gateway v2

Package Exports

  • serverless-apigateway-route-settings

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (serverless-apigateway-route-settings) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

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.