Skip to content

SAM Api Gateway cache with queryStringParam and PathParam #1140

@IstvanSzilagyi

Description

@IstvanSzilagyi

Description:
I would like to enable chaching for the API Gateway which distinguish requests based on QueryStringParameters and RequestParameters/PathParams, I was able to enable cache for the ServerlessRestApi but for some reasion doesn't matter what i do it just ignores the params defined. At this point im not even sure if this is an issue or bug, but this would be nice to know/have a feature where i could just simply define my Methods in the global section of a cloudformation template, and would include params(both query and path params) in caching.

I also made a stack overflow question regarding this, for more details please check: https://stackoverflow.com/questions/57907320/aws-enable-caching-with-querrystringparameter-pathparameter-for-sam-api-gateway

Example Yaml template

`AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Globals:
  Api:
    EndpointConfiguration: REGIONAL
    CacheClusterEnabled: true
    CacheClusterSize: "0.5"
    MethodSettings: 
      - CachingEnabled: true
        CacheDataEncrypted: true
        CacheTtlInSeconds: 60
        HttpMethod: "*"
        ResourcePath: "/*"
     - ResourcePath: "/~1item~1/~1{itemCode}"
        CachingEnabled: true
        CacheDataEncrypted: true
        CacheTtlInSeconds: 60
        HttpMethod: "*"
Resources:
......
  GetItem:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: GetItem.handler
      Runtime: nodejs8.10
      Timeout: 20
      CodeUri: "codes"
      Events:
        GetItem:
          Type: Api
          Properties:
            Path: /item/{itemCode}
            Method: get
......`

Observed result:
Caching not enabled for params thus returning incorrect response

Expected result:
Enable caching for params and distingush requests based on the params.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions