AWS API Gateway caching ignores query parameters

The following is how we can achieve this utilising SAM:

The end result in the AWS API Gateway console must display that the set caching checkbox is:

enter image description here

The *.yml template for the API Gateway would be:

Resources:
  MyApi:
    Type: AWS::Serverless::Api
    Properties:
      StageName: Prod
      CacheClusterEnabled: true
      CacheClusterSize: '0.5'
      MethodSettings:
        - HttpMethod: GET
          CacheTtlInSeconds: 120
          ResourcePath: "/getData"
          CachingEnabled: true
      DefinitionBody:
        swagger: 2.0
        basePath: /Prod
        info:
          title: OutService
        x-amazon-apigateway-policy:
          Version: "2012-10-17"
          Statement:
            - Effect: Allow
              Principal: "*"
              Action: execute-api:Invoke
              Resource:
                - execute-api:/*/*/*
        paths:
          "/getData":
            get:
              # ** Parameter(s) can be set here **
              parameters:
                - name: "path"
                  in: "query"
                  required: "false"
                  type: "string"
              x-amazon-apigateway-integration:
              # ** Key is cached **
                cacheKeyParameters:
                  - method.request.querystring.path
                httpMethod: POST
                type: aws_proxy
                uri:
                  Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${OutLambda.Arn}/invocations
              responses: {}
      EndpointConfiguration: PRIVATE
      Cors:
        AllowHeaders: "'*'"

You need to configure this option in the Gateway API panel.

  • Choose your API and click Resources.
  • Choose the method and see the URL Query String session.
  • If there is no query string, add one.
  • Mark the "caching" option of the query string.
  • Perform the final tests and finally, deploy changes.

Screenshot