AWS Certified Developer - Associate

API Gateway

Caching Demo

In this lesson, we will guide you through the steps necessary to configure caching for your AWS API Gateway. Proper caching not only enhances your API's performance by storing responses for a specified duration but also helps manage traffic more effectively.

Step 1: Select and Edit the API Stage

Begin by navigating to your API and choosing the specific stage for which you want to configure caching. Remember, each stage can have its own unique configuration settings. Once you have selected the correct stage, click Edit to access the stage configuration.

Within the stage configuration, locate the cache settings. Activating these settings provisions a cache for your API. However, note that caching remains inactive until you explicitly enable method-level caching. Even when stage-level caching is configured, you must enable it for each API method individually. Alternatively, you may opt to activate caching automatically for all GET methods.

Step 2: Customize Caching Parameters

You have the flexibility to adjust several caching parameters at the stage level:

  • Define the cache capacity.
  • Enable data encryption to secure your cached data.
  • Set the TTL (Time-To-Live), which determines how long cached responses remain valid.
  • Activate authorization in the cache to manage interactions with unauthorized requests.

Customization Tip

When cache authorization is enabled, you can configure the response for unauthorized invalidation attempts. Options include ignoring the header, issuing a warning, or returning a 403 status code.

The image shows an AWS API Gateway settings page, where options for caching, throttling, and firewall settings are being configured. The page includes dropdown menus and toggle switches for various settings.

Step 3: Configure Caching for Individual API Methods

Caching can also be tailored for individual API methods. To enable this:

  1. Navigate to the specific method and click Edit.
  2. In the method configuration page, enable method-level caching.
  3. Adjust parameters such as TTL or cache capacity to override stage-level settings if necessary.

The image shows a configuration page from AWS API Gateway, detailing settings for API caching, throttling, and firewall and certificate options.

Further adjustments can be made directly in the method's override settings:

The image shows the "Edit method overrides" settings page in AWS API Gateway, where options for CloudWatch logs, throttling, method cache, and cache time-to-live are configured.

Conclusion

By following these steps, you can effectively set up and customize caching in AWS API Gateway. This configuration not only enhances your API performance by reducing response times but also helps in managing traffic by efficiently handling repeated requests.

For additional details and advanced configurations, consider reviewing the AWS API Gateway Documentation.

Watch Video

Watch video content

Previous
Caching