Part 5 - Confirm Throttling with Load Test Script

There are several ways we can confirm that requests are now being throttled. If you’re familiar with Postman, you can run multiple iterations using the Collection Runner feature to run multiple iterations with no delay between each request. If you’re not familiar with Postman’s Collection Runner feature, you can create a simple PowerShell script by following the steps below that will demonstrate the throttling feature of the API Gateway API.

1. Copy the below code to a text file, and save it with the extension “.ps1”. Make sure you replace <your-api-gateway-invoke-url> with the actual Invoke URL of your API, so that the URL ends with /prod/api/values.

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

   for ($i = 0; $i -lt 10; $i++) {
      Invoke-WebRequest -Uri https://*<your-api-gateway-invoke-url>*/prod/api/values -Method 'Get'

2. Open PowerShell, and navigate to the folder where you saved the file. Run your PowerShell script by typing .\<file-name>.ps1 (no quotes) 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 and the json payload, while others will fail with the response json, {“message”:“Too Many Requests”}.

If you are running the iterations in Postman, you will see that the response HTTP status code is 429 (Too Many Requests).