2.0.3 • Published 1 year ago

serverless-api-gateway-throttling v2.0.3

Weekly downloads
9,648
License
ISC
Repository
github
Last release
1 year ago

serverless-api-gateway-throttling

CircleCI npm npm downloads

Intro

A plugin for the Serverless framework which configures throttling for API Gateway endpoints.

Why?

When you deploy an API to API Gateway, throttling is enabled by default. However, the default method limits – 10,000 requests/second with a burst of 5000 concurrent requests – match your account level limits. As a result, ALL your APIs in the entire region share a rate limit that can be exhausted by a single method. Read more about that here.

This plugin makes it easy to configure those limits. It supports both API Gateway v1 (REST API) and API Gateway v2 (HTTP API).

Good to know

  • if custom throttling settings are defined for an endpoint with HTTP method ANY, the settings will be applied to all methods: GET, DELETE, HEAD, OPTIONS, PATCH, POST and PUT.

How this plugin works

It configures endpoints in the gateway to override the settings they inherit from the stage. If you need reset all endpoints to inherit their settings from the stage again (as seen in this issue), you can do this:

sls reset-all-endpoint-settings

Examples

plugins:
  - serverless-api-gateway-throttling

custom:
  # Configures throttling settings for the API Gateway stage
  # They apply to all http endpoints, unless specifically overridden
  apiGatewayThrottling:
    maxRequestsPerSecond: 1000
    maxConcurrentRequests: 500

functions:
  # Throttling settings are inherited from stage settings
  update-item:
    handler: rest_api/item/post/handler.handle
    events:
      - http:
          path: /item
          method: post

  # Requests are throttled using this endpoint's throttling configuration
  list-all-items:
    handler: rest_api/items/get/handler.handle
    events:
      - http:
          path: /items
          method: get
          throttling:
            maxRequestsPerSecond: 2000
            maxConcurrentRequests: 1000

  # Requests are throttled for both endpoints
  get-item:
    handler: rest_api/items/get/handler.handle
    events:
      - http: # throttling settings are inherited from stage settings
          path: /item/{itemId}
          method: get
      - http:
          path: /another/item/{itemId}
          method: get
          throttling:
            maxRequestsPerSecond: 2000
            maxConcurrentRequests: 1000

  # Requests are throttled for both endpoints
  get-blue-item:
    handler: rest_api/items/blue/get/handler.handle
    events:
      - http:
          path: /item/blue/{itemId}
          method: get
          throttling:
            maxRequestsPerSecond: 300
            # maxConcurrentRequests are inherited from stage settings
      - http:
          path: /item/dark-blue/{itemId}
          method: get
          throttling:
            # maxRequestsPerSecond are inherited from stage settings
            maxConcurrentRequests: 300

  # Throttling is disabled for this endpoint
  list-more-items:
    handler: rest_api/items/get/handler.handle
    events:
      - http:
          path: /more-items
          method: get
          throttling:
            disabled: true
  
  # Also supports httpApi
  list-http-api-items:
    handler: rest_api/items/get/handler.handle
    events:
      - httpApi:
          path: /http-api-items
          method: get
          throttling:
            maxRequestsPerSecond: 3000
            maxConcurrentRequests: 1000
2.0.3

1 year ago

2.0.3-rc1

1 year ago

2.0.0-rc4

2 years ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

2.0.1-rc2

2 years ago

2.0.1-rc1

2 years ago

2.0.1-rc3

2 years ago

2.0.1-rc5

2 years ago

2.0.0-rc3

2 years ago

2.0.0-rc2

2 years ago

2.0.0-rc1

2 years ago

1.2.2

2 years ago

1.2.0

2 years ago

1.2.1

2 years ago

1.2.0-rc5

2 years ago

1.2.0-rc4

2 years ago

1.2.0-rc3

2 years ago

1.2.0-rc2

2 years ago

1.2.0-rc1

2 years ago

1.2.1-rc1

2 years ago

1.1.1

3 years ago

1.1.1-rc1

3 years ago

1.1.0

3 years ago

1.1.0-rc1

3 years ago

1.0.2

3 years ago

1.0.2-rc3

3 years ago

1.0.2-rc2

3 years ago

1.0.2-rc1

3 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-rc4

4 years ago

1.0.0-rc3

4 years ago

1.0.0-rc2

4 years ago

1.0.0-rc1

4 years ago