Justin Kruse
Justin Kruse

Reputation: 1130

Serverless and AWS: API Gateway Override Stage to Cache Method

I am using the Serverless framework with AWS and I have enabled caching in my stage and set the stage MethodSettings -> Enable Caching to false so all methods do not cache. I would like to enable caching for specific methods and see that I can override the stage settings in the console. What config value needs to be set to allow me to do this from the Serverless CF template?

UPDATE:

I've done the following in my serverless.yml

ApiGatewayStage:
  Type: "AWS::ApiGateway::Stage"
  Properties:
    CacheClusterEnabled: true
    CacheClusterSize: "1.6"
    MethodSettings:
      - ResourcePath: "/*"
        HttpMethod: "*"
        CachingEnabled: false
      - ResourcePath: "/~1events~1{eventId}~1geo~1{ipAddress}"
        HttpMethod: "*"
        CacheDataEncrypted: true
        CacheTtlInSeconds: ${self:provider.environment.API_GATEWAY_CACHE_TTL}
        CachingEnabled: true

I would expect his to set caching to false for all methods, but then override the given resource on the stage to enable caching.

Upvotes: 2

Views: 1453

Answers (1)

Justin Kruse
Justin Kruse

Reputation: 1130

My issue was incorrect encoding of the ResourcePath. The above is correct with:

ResourcePath: "/~1events~1{eventId}~1geo~1{ipAddress}"

However, my script I wrote to automate this did not have the first ~1 after the initial slash. I did not notice this until I printed it out and stared at it... for far too long.

Upvotes: 1

Related Questions