The `serverless-api-gateway-caching` plugin for the Serverless Framework simplifies the configuration of caching for AWS API Gateway REST API endpoints. Its current stable version is 1.11.0. This plugin allows developers to define caching settings both globally for an API Gateway stage and granularly for individual endpoints, including time-to-live (TTL), data encryption, and cache key parameters. It provides fine-grained control over which request elements (path, header, query string) contribute to the cache key. A crucial differentiator is its explicit support for *only* REST API Gateway, as AWS HTTP API does not support native caching at this time. Releases are regular, often driven by bug fixes and minor feature enhancements, making it an actively maintained tool for optimizing API performance and reducing backend load for Serverless applications.
npm install serverless-api-gateway-cachingNo compatibility data collected yet for this library.
This `serverless.yml` configuration demonstrates how to enable the `serverless-api-gateway-caching` plugin, define global caching settings for an API Gateway stage, and then apply and override those settings for specific REST API endpoints, including configuring custom cache key parameters.
Ensure your Serverless `http` events define `rest` APIs, not `http` APIs. This plugin is not applicable for HTTP APIs.
For each endpoint requiring caching, add `caching: enabled: true` within its `http` event configuration in `serverless.yml`.
Review existing `cacheKeyParameters` configurations. If a parameter should be required for cache key generation, explicitly add `required: true` to its definition, e.g., `- name: request.path.pawId required: true`.
If your API Gateway methods relied on the previous default `{}` for `Method RequestParameters`, explicitly define your desired `method.request.parameters` to match the intended behavior in your `serverless.yml`.Upgrade to version 1.8.1 or newer. When defining `cacheKeyParameters` for headers, ensure consistent casing with how API Gateway expects them or as they are received.
The plugin is only compatible with AWS API Gateway REST APIs. Ensure your `serverless.yml` uses `rest` for `http` events or switch to a REST API if currently using HTTP API.
For each specific HTTP endpoint you wish to cache, you must add `caching: enabled: true` within its event configuration in `serverless.yml`.
Upgrade `serverless-api-gateway-caching` to version 1.8.1 or higher. Ensure correct casing for header names if this issue persists.
Upgrade to version 1.10.2 or newer to resolve issues with uninitialised settings. Review your `apiGatewayCaching` configuration to ensure all necessary properties are defined.