Enabling API Gateway Caching and Throttling
You can configure throttling and caching independently for each API Gateway stage. For example, you may want to avoid throttling and caching on your dev stage, and enable them on your prod stage.
Please note that although throttling is free, caching is provided by a custom instance whose size and cost depend on the selected cache capacity (from 500MB to 237GB). Optionally you can encrypt your cache data, set up a time-to-live (TTL) in seconds and require authorization for cache invalidation requests.
You will configure caching and throttling for the prod stage in this Lab Step.
1. Select the prod stage, check Enable API cache main Settings tab and enter the following values:
- Cache capacity: 0.5GB
- Encrypt cache data: Checked
- Cache time-to-live (TTL): 3600
- Require authorization: Checked
- Handle unauthorized requests: Fail the request with a 403 status code
2. Scroll down to the Default Method Throttling section and ensure that Enable throttling is checked and accept the default values:
3. Click Save Changes at the bottom of the tab.
In case you have special customers and you want to limit their access to your API, you can configure the throttling and daily/weekly/monthly quota on the corresponding Usage Plan.
4. Select Usage Plans > CloudAcademyPlan > Details > Edit and observe the Throttling and Quota sections:
You can set usage plan-level limits here.
5. Check Enable quota and enter a quota of 1000 requests per Day before clicking Save:
This configuration will ensure that each individual user (as identified by unique API keys) won't consume your stage/account capacity. Of course, you can monitor and update these configurations at any time, even after creating a Usage Plan or an API Key.
In this Lab Step, you enabled API caching and throttling on the prod stage. You also enabled a quota at the usage plan-level to limit the number of requests authorized by an API Key per day.