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

Configuration Error in Serverless@2.19.0 #84

Closed marc-parillo closed 3 years ago

marc-parillo commented 3 years ago

Plugin is throwing errors when trying to deploy.

 Serverless Error ---------------------------------------

 Configuration error at 'functions.connect.events[0]': unrecognized property 'caching'

 Your Environment Information ---------------------------
     Operating System:          darwin
     Node Version:                 12.16.1
     Framework Version:       2.19.0
     Plugin Version:               4.4.2
     SDK Version:                  2.3.2
     Components Version:   3.4.7
connect:
    handler: connect/gateway/index.handler
    description: Test API Connection
    events:
      - http: 'GET /test/connect'
        caching:
          enabled: true
          ttlInSeconds: 3600
marc-parillo commented 3 years ago

I found that it does work when the per-function level configuration is placed under custom like this (instead of below each function as in my earlier comment).

custom:
  apiGatewayCaching:
    enabled: true
    ttlInSeconds: 1
    additionalEndpoints:
      - method: GET
        path: /test/connect
        caching:
          enabled: true
          ttlInSeconds: 150
DianaIonita commented 3 years ago

Hi @marc-parillo,

Thanks for raising the issue. My guess is that the apiGatewayCaching configuration was missing in your first example.

This should work:

custom:
  apiGatewayCaching:
    enabled: true

functions:
  connect:
    handler: connect/gateway/index.handler
    description: Test API Connection
    events:
      - http: 'GET /test/connect'
        caching:
          enabled: true
          ttlInSeconds: 3600

The additionalEndpoints feature is only recommended for when an endpoint is defined in CloudFormation, like in this example. The additionalEndpoints section doesn't support things like cacheKeyParameters.

Please let me know if you still have problems.

marc-parillo commented 3 years ago

Thanks for merging my PR and your updated version 1.6.1!

I was testing out different configuration settings based on your suggestions and Serverless@2.19.0 still throws errors.

Example 1

custom:
  apiGatewayCaching:
    enabled: true

functions:
  cached:
    handler: cached/gateway/index.handler
    description: Test API Caching
    events:
      - http: 'GET /cached'
        caching:
          enabled: true
          ttlInSeconds: 30

Example 2

custom:
  apiGatewayCaching:
    enabled: true

functions:
  cached:
    handler: cached/gateway/index.handler
    description: Test API Caching
    events:
      - http:
        path: /cached
        method: get
        caching:
          enabled: true
          ttlInSeconds: 30

Same Error Both Times

Serverless Error ---------------------------------------
  Configuration error at 'functions.cached.events[0]': unrecognized property 'caching'

At the top of my .yml file, I do have a command to throw configuration errors

service: api-test
configValidationMode: error

So, I tried disabled configValidationMode: error. Serverless stopped throwing theunrecognized property 'caching' error. I checked API Gateway after deploying, the cache settings in my .yml file did not propagate to API Gateway. In other words, caching for that particular endpoint was not enabled and the ttlInSeconds was not set to 30 as expected.

marc-parillo commented 3 years ago

Closing this issue. It works fine. I didn't indent everything below http: correctly.

events:
      - http:
            path: /cached
            method: get
            caching:
              enabled: true
              ttlInSeconds: 30