API Gateway 캐시 클러스터 미설정

캐시가 적합한 REST API에 응답 캐시를 구성하세요.

설명

같은 REST API 요청이 백엔드에 반복해서 도달하고 응답을 재사용해도 되는 경우 스테이지 캐싱을 켜세요.

잠재적 영향

캐싱은 백엔드 호출과 지연을 줄일 수 있습니다. 캐시 키나 만료 시간이 잘못되면 다른 사용자의 응답이나 오래된 데이터가 전달될 수 있습니다.

해결 방법

스테이지에 CacheClusterEnabled: true, 대상 메서드에 CachingEnabled: true를 설정하세요. 사용자나 입력에 따라 응답이 달라지면 이를 캐시 키로 구분하고 응답을 재사용해도 되는 시간을 정하세요.

예시

예시는 모든 경로의 GET 응답을 캐싱합니다. 적용할 경로를 정하고 MyRestApi와 MyDeployment를 지정하세요.

변경 전

yaml
Resources:
  ProdStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      StageName: Prod
      RestApiId: !Ref MyRestApi
      DeploymentId: !Ref MyDeployment
      TracingEnabled: true

변경 후

yaml
Resources:
  ProdStage:
    Type: AWS::ApiGateway::Stage
    Properties:
      StageName: Prod
      RestApiId: !Ref MyRestApi
      DeploymentId: !Ref MyDeployment
      TracingEnabled: true
      CacheClusterEnabled: true
      MethodSettings:
        - ResourcePath: /*
          HttpMethod: GET
          CachingEnabled: true

참조