AWS API Gateway - Throttling Specific End Point

Hi,
I think I have found an issue with serverless that means I am unable to throttle a specific API end point.

I have a legacy system that I call via a lambda on my API Gateway. It cannot handle ‘load’ of more than one call per second. It is one of a bunch of end points in my gateway.

I cannot find a way to specifically throttle ‘just’ this end point using serverless or the resources section.

What I have found is that I can set up -:

  1. Usage Plan to ALL end points in the gateway.
  2. Used the serverless plug in to configure that default Throttling

However - as I have said above I cannot find a way to target a specific end point.

Does anyone here have any experience of this?

regards

Richard.

Hi Richard,

As far as I am aware, you are correct in saying the Serverless Framework does not offer a way to configure method-level throttling natively via the serverless.yml file.

I have found a similar discussion going on in this GitHub issue, and the two solutions that have been offered are:

Hope this helps!

Hi Teddy,
Thanks for your input on this tricky problem, I’m learning a lot! I have taken a look at both of these options. Keep in mind the Gateway is already created and I want to change this one setting of a particular end point.

  1. Using Resources Section with Method Level

1.1 Create a “AWS::ApiGateway::Stage” , then on MethodSettings set a “MethodSetting” - and set the Throttling here. This is all good but when I go to deploy I am not understand what I should set the ‘RestApiId’ property?
The end section of this link gives a good demonstration on achieve this -: https://serverless.com/framework/docs/providers/aws/guide/resources/

  1. [serverless-api-stage] plugin. I’ve tried this approach bit I’ve only been able to set the stage level variables which are then mapped to methods. Looking at the code on GitHub would seem to back up my findings because in ( https://github.com/leftclickben/serverless-api-stage/blob/master/src/index.js - line 121) - you can see that it maps any method settings to all methods. So again - not allowing you to actually identify a specific end point.

Hope this all makes sense. Any help with the RestAPIID when you have just created the end point would be really useful.

ergads

Rich

I know this is hideous but why not write a timestamp to DynamoDB every time the endpoint is called and check if the elapsed time is >1000ms each time you call it? Don’t tell me it’s gross. I already know that. lol. It should work, though.

Hi Mr @RichardHill, could you please share the way you handled to set the default Throttling ?

Regards,
Hamlet

Hi,

I’m also interested in this feature of specific endpoint throttling rate and burst. It’s possible to set this up via AWS Console under ApiGateway -> Service -> Stages -> *stage* -> endpoint http verb -> Default Method Throttling and the configuration is kept after a new deploy.
However it doesn’t seem possible to configure it using serverless.yml, which would be nice.

If you have any news on this topic, don’t hesitate to notify :slight_smile:

You can use Ref: ApiGatewayRestApi to set the rest api id.

Is this still the case? There is no way to throttle a specific endpoint using the http event? It looks like it is a simple enough process in AWS using the command line: Throttling requests to your HTTP API - Amazon API Gateway, like this:

aws apigatewayv2 update-stage \
    --api-id a1b2c3d4 \
    --stage-name dev \
    --route-settings '{"GET /pets":{"ThrottlingBurstLimit":100,"ThrottlingRateLimit":2000}}'

Would be great to have this as a built in feature.