ion icon indicating copy to clipboard operation
ion copied to clipboard

How to handle AWS cache policy limit

Open nserbass opened this issue 1 year ago • 3 comments

Use case: My team is using SST to deploy a Nextjs application in multiple stage environments for testing feeatures before deploy to production (another env deployed by sst).

Problem: Due to aws cloudfront cache policy limit, we can't create too many environments because we reach the limit quickly (20)

I've followed your documentation about transform function. I've tried several implementations but always creates a new one and throws errors with missing defaultCacheBehavior parameters:

new sst.aws.Nextjs("MyWeb", {
  environment,
  transform: {
    cdn: {
      defaultCacheBehavior: {
        cachePolicyId: 'f99c40f2-50bf-4215-8023-125e7a46fb0e'
      }
    }
  },
});
new sst.aws.Nextjs("MyWeb", {
  environment,
  transform: {
    cdn: (cdnArgs) => {
      cdnArgs.defaultCacheBehavior = {
        cachePolicyId: 'f99c40f2-50bf-4215-8023-125e7a46fb0e'
      }
    }
  },
});
// it doesn't throw errors but creates a new cache policy as well
new sst.aws.Nextjs("MyWeb", {
  environment,
  domain: customDomain,
  transform: {
    cdn: (args) => ({
      ...args,
      defaultCacheBehavior: {
        ...args.defaultCacheBehavior,
        cachePolicyId: 'f99c40f2-50bf-4215-8023-125e7a46fb0e'
      }
    })
  }
});

Any ideas?

Thank you!

nserbass avatar May 04 '24 13:05 nserbass