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 -:
Usage Plan to ALL end points in the gateway.
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.
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:
Using the resources section of the serverless.yml file to configure method-level throttling using the appropriate CloudFormationconfiguration (ThrottlingRateLimit).
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.
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/
[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.
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.
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
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: