WebSocket Rate Limiting

0

In API Gateway service, We'd like to control users websocket connections and messages send over connections.

Is it possible to achieve below by utilizing WebSocket feature?

  • Rate limit the number of WebSocket connections each user (or API key) can have at a time.
  • Rate limit the number of messages in a WebSocket connection.
  • Extract (Logging) WebSocket messages for processing websocket access logs afterwards. Thank you
asked 5 months ago317 views
2 Answers
0

Use API Gateway's throttling feature to control the number of WebSocket connections per user or API key.

https://www.beabetterdev.com/2021/10/01/aws-api-gateway-request-throttling/

Similar to connection throttling, you can set limits on the number of messages per WebSocket connection by configuring route-level throttling in API Gateway​​. For logging WebSocket messages, employ a Lambda Authorizer, which can be used for access control and message logging, as direct usage plans for WebSocket are not available like they are for HTTP connections​

https://github.com/aws-samples/api-gateway-websocket-saas-rate-limiting-using-aws-lambda-authorizer

profile picture
EXPERT
answered 5 months ago
  • Hello, Thank you for commenting! I've checked API Gateway console and trying to configure it.

    However,

    Use API Gateway's throttling feature to control the number of WebSocket connections per user or API key.

    Different from HTTP/REST, WebSocket API doesn't have throttling setting section in console as I attached an image below, and linked article doesn't include topics about Websocket specifically (for e.g. how to configure websocket connections limit per apikey) Is it configurable by CLI?

    Similar to connection throttling, you can set limits on the number of messages per WebSocket connection by configuring route-level throttling in API Gateway​​.

    Do you mean Account throttling by route-level throttling in API Gateway? It has two values "Burst limit" and "Rate limit", do they apply to WebSocket messages as well? (The background of asking this is most of API Gateway services' rate limit doesn't apply to WebSocket messages due to its protocol uniqueness)

    For logging WebSocket messages, employ a Lambda Authorizer

    Thank you! I'll go deeper into this.

    Basically, We'd like to apply WebSocket connections limit and messages limit in a connection "per api key".

0

Enter image description here

answered 5 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions