I'm trying to enable API Gateway throttling, but it's not working as expected.
I set Default Method Throttling Rate to 1 request per second, and Burst to 1 request.
Then I created a loop in my code to make 10 simultaneous requests to my API endpoint.
for (let i=0; i<10; i++) {
axios.get(url);
}
The expected result would be:
- 1 successful request
- 9 throttled requests (HTTP 429 error)
But the actual result was the opposite:
- 9 successful requests
- 1 throttled request (HTTP 429 error)
I repeated the process, but making 20 simultaneous request and the result was:
- 16 successful requests
- 4 throttled requests (HTTP 429 error)
On CloudWatch logs for this API method, I found different Log streams, each one with only few milliseconds difference.
If I set Rate to 0 requests per second and Burst to 0 request, the throttling works and ALL requests get throttlet. But when I set Rate and Bust to 1 it does not work as expected.
Why is that happening? I need to limit my API to only 1 request per second.