Test throttling

In this module you will test throttling configuration of Amazon API Gateway using simple load test script.

You can access the Default Method Throttling configuration by navigating to:

  1. Stages
  2. Click on the stage (eg Prod)
  3. Enable Throttling

Change the throttling values to 1 request/second, with a burst rate of 2 requests. We’re choosing this low value to make it easier to test without load-testing software. Save your changes.

Throttling

Create the new PowerShell script file with the following content (use your API Gateway URL):

Write-Output "Sending GET request to your REST endpoint 10 times"

for ($i = 0; $i -lt 10; $i++) {
    Invoke-WebRequest -Uri https://<Your API Endpoint URL>/Prod/api/values -UseBasicParsing -Method 'Get'
}

Open PowerShell, and navigate to the folder where you saved the file. Run your PowerShell script by typing .\<file-name>.ps1 where <file-name> is the name you gave the file.

Depending on your network connection, and the speed at which your computer is able to execute the requests, you will see some of the requests succeed with status code 200, while others will fail with the {“message”:“Too Many Requests”} error message indicating that requests were throttled.

StatusCode        : 200
StatusDescription : OK
RawContent        : HTTP/1.1 200 OK
                    Connection: keep-alive
                    Date: Wed, 07 Apr 2021 10:33:39 GMT
                    x-amzn-RequestId: 2d4c071a-afcc-473d-a13d-463fa83e2599
                    x-amz-apigw-id: daKUkHH3DoEFYTA=
                    X-Amzn-Trace-Id: Root=1-606d8a83…
Headers           : {[Connection, System.String[]], [Date, System.String[]], [x-amzn-RequestId, System.String[]],
                    [x-amz-apigw-id, System.String[]]…}
RawContentLength  : 45
RelationLink      : {}

Invoke-WebRequest: C:\Projects\test.ps1:4
Line |
   4 |      Invoke-WebRequest -Uri https://u8sjskar3c.execute-api.eu-west-1.a …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | {"message":"Too Many Requests"}

Invoke-WebRequest: C:\Projects\test.ps1:4
Line |
   4 |      Invoke-WebRequest -Uri https://u8sjskar3c.execute-api.eu-west-1.a …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | {"message":"Too Many Requests"}