DianaIonita / serverless-api-gateway-caching

A plugin for the Serverless framework which helps with configuring caching for API Gateway endpoints.
ISC License
136 stars 35 forks source link

Miss from cloudfront #53

Closed webchaz closed 5 years ago

webchaz commented 5 years ago

Should this be showing a hit from cloudfront if configured correctly?

This is what I have and doesn't seem to be caching:

custom:
  splitStacks:
    perFunction: true
    perType: true
  warmup:
    enabled: true
    events:
      - schedule: rate(15 minutes)
    prewarm: true
  apiGatewayXray: false
  baseUrl: v1
  prune:
    automatic: true
    number: 2
  apiGatewayCaching:
    enabled: true

plugins:
  - serverless-plugin-split-stacks
  - serverless-plugin-warmup
  - serverless-prune-plugin
  - serverless-api-gateway-caching

For functions:

getStats:
  handler: src/functions/reports.getStats
  events:
    - http:
        path: ${self:custom.baseUrl}/reports/stats
        method: get
        private: true
        cors: true
        caching:
          enabled: true

Thank you!

webchaz commented 5 years ago

Just a follow up to this, when this enabled, should the stage settings in API Gateway have Cache enabled?

djakaitis commented 5 years ago

Seeing the same issue with the exact same setup

webchaz commented 5 years ago

@djakaitis Looks like the cache-hit from CloudFront is not an indication of cache working or not. I had stepped away from this, but not sure if there's a way to verify.

djakaitis commented 5 years ago

@webchaz I just verified it is working correctly by checking cloudwatch lambda logs. No lambda is being invoked as a result of the api cache. When I flushed the cache the next invocation hit lambda.

webchaz commented 5 years ago

@djakaitis That's a great idea, i guess just absence of a log is that it hit cache. Thanks, will check that out.

DianaIonita commented 5 years ago

@webchaz API Gateway has its own cache instance under the hood, it's not the same as CloudFront (more details). You wouldn't see a cache hit from CloudFront after you enable this plugin.

One other way to check that your request is coming from the cache, aside from checking lambda logs, is to add a response header with the ISO timestamp and check that it stays the same across requests.

webchaz commented 5 years ago

@DianaIonita Thanks for this, tried this out, but it's not working. Should API Cache be enabled within API Gateway? With this enabled, it caches everything, without regard to the settings, with it disabled, just no dice.