serverless-appsync-plugin icon indicating copy to clipboard operation
serverless-appsync-plugin copied to clipboard

Feature request: Add `enabled` option for caching

Open joebernard opened this issue 4 years ago • 6 comments

I have an AppSync config that I deploy to multiple environments. Only one of those environments should have caching enabled (production). Unfortunately, I can't find a way to enable/disable the caching config during deployment.

What would be ideal for my use case and remain consistent with other settings is to add an enabled option in the caching config.

caching:
  enabled: true # globally turns caching on or off [true|false]
  behavior: PER_RESOLVER_CACHING
  ttl: 60
  type: "SMALL"

I could then set this based on the environment I'm in. Is this possible to add, or is there another way to dynamically configure caching?

joebernard avatar Jul 18 '21 18:07 joebernard

I have the same use case. I can take a stab at implementation if no work has been done on it yet.

quickliketurtle avatar Feb 16 '22 19:02 quickliketurtle

I didn't attempt an implementation but we could definitely use it.

joebernard avatar Feb 16 '22 20:02 joebernard

Sorry, I missed this.

A setting would be great, indeed. Thank you for your suggestion.

As a workaround, here is how we've used it in some projects:

caching: ${file(templates/macros.js):getAppSyncCachingConfig}

in templates/macros.js

const getStage = (serverless) => {
  const { stage } = serverless.options
    ? serverless.options
    : serverless.service.provider;

  return stage;
};

module.exports = {

  getAppSyncCachingConfig(serverless) {
    return ['staging', 'prod'].some((s) => getStage(serverless).startsWith(s))
      ? {
          behavior: 'PER_RESOLVER_CACHING',
          ttl: 60,
          type: 'SMALL',
        }
      : false;
  },

};

bboure avatar Feb 17 '22 11:02 bboure

Sorry, I missed this.

A setting would be great, indeed. Thank you for your suggestion.

As a workaround, here is how we've used it in some projects:

caching: ${file(templates/macros.js):getAppSyncCachingConfig}

in templates/macros.js

const getStage = (serverless) => {
  const { stage } = serverless.options
    ? serverless.options
    : serverless.service.provider;

  return stage;
};

module.exports = {

  getAppSyncCachingConfig(serverless) {
    return ['staging', 'prod'].some((s) => getStage(serverless).startsWith(s))
      ? {
          behavior: 'PER_RESOLVER_CACHING',
          ttl: 60,
          type: 'SMALL',
        }
      : false;
  },

};

We also have a use case for this cause if you leave caching on (SMALL) it will cost about 30 euros per month. When you have an environment per developer that goes up quickly.

This is a clean workaround though! Thanks.

Nxtra avatar Mar 21 '22 11:03 Nxtra

hi @bboure checking the v2 branch: looks like the option for conditional enabling it is still missing?

jmvalino avatar Apr 20 '22 01:04 jmvalino

@jmvalino it is I think it's just not documented (yet). Thanks for raising this.

bboure avatar Apr 20 '22 13:04 bboure