serverless-api-gateway-caching icon indicating copy to clipboard operation
serverless-api-gateway-caching copied to clipboard

Configuring with serverless-apigateway-service-proxy plugin

Open toddpla opened this issue 4 years ago • 1 comments

Is this plugin able to be configured with serverless-apigateway-service-proxy?

Specifically I would like to enable caching of a dynamodb GET request via an API Gateway proxy.

toddpla avatar Jan 17 '21 17:01 toddpla

Hi @toddpla,

Thanks for asking. Yes, the serverless-api-gateway-caching plugin can work with the serverless-apigateway-service-proxy. There's a feature which allows configuring caching for endpoints that are not defined as lambda functions. The example in this plugin's readme shows a proxy endpoint defined in CloudFormation syntax, but the same kind of configuration works no matter how endpoints are defined.

In yml, the plugins working together might look like this:

plugins:
  - serverless-api-gateway-caching
  - serverless-apigateway-service-proxy

custom:
  apiGatewayCaching:
    enabled: true
    additionalEndpoints:
      - method: GET
        path: /dynamodb # needs to match the path defined in apiGatewayServiceProxies
        caching:
          enabled: true
  apiGatewayServiceProxies:
    - dynamodb:
        path: /dynamodb
        method: get
        tableName: { Ref: 'MyDynamoTable' }
        hashKey:
          queryStringParam: id # use query string parameter
          attributeType: S
        action: GetItem

That said, the additionalEndpoints feature does not currently support configuring cache key parameters.

If you call /dynamodb?id=1, it will cache the result for id=1. If you then call /dynamodb?id=2, it will retrieve the result it had cached for id=1 until the cache time to live expires. Based on your requirements, you may wish to wait for this feature to be added before using these plugins side by side.

DianaIonita avatar Feb 07 '21 21:02 DianaIonita

Released in 1.9.0

DianaIonita avatar Sep 21 '22 13:09 DianaIonita