SAM API cache cluster not configured

Configure caching for a SAM REST API according to its responses.

Description

A cache cluster on AWS::Serverless::Api can reuse responses and reduce repeated backend calls. Caching is optional; choose its scope to avoid serving stale data or sharing user-specific responses incorrectly.

Potential impact

A workload with many cacheable requests may incur more backend load and latency without caching.

Remediation

Set CacheClusterEnabled: true where appropriate, and enable caching for the intended methods through MethodSettings. Also choose cache keys and expiry.

Examples

The examples enable caching for GET methods. Configure the actual API definition and response-specific cache keys separately.

Before

yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
      TracingEnabled: true

After

yaml
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Resources:
  ApiGatewayApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: prod
      TracingEnabled: true
      CacheClusterEnabled: true
      MethodSettings:
        - ResourcePath: /*
          HttpMethod: GET
          CachingEnabled: true

References