serverless-next.js icon indicating copy to clipboard operation
serverless-next.js copied to clipboard

When deploying multiple apps via CDK I hit the cache policy limit on my account

Open kirkness opened this issue 4 years ago • 2 comments

Is your feature request related to a problem? Please describe. Deploying multiple apps under one account will create 3 cache policies per app, an account can only have up to 20 so you hit the limit pretty quick.

Describe the solution you'd like

  1. Hoist the cache policies to the top of the stacks
  2. Allow users to pass in their own policies
  3. Implement some API for nextApp.resuseCachePolicies(otherNextApp)

kirkness avatar Mar 12 '21 14:03 kirkness

Once #955 is merged it'll be an easy change to add an optional prop to the construct for each of the cache policies:

const appOne = new NextJSLambdaEdge(...);
const appTwo = new NextJSLambdaEdge(..., {
  nextStaticsCachePolicy: appOne.nextStaticsCachePolicy,
  nextImageCachePolicy: appOne.nextImageCachePolicy,
  nextLambdaCachePolicy: appOne.nextLambdaCachePolicy,
});

kirkness avatar Mar 18 '21 12:03 kirkness

In case anyone else hits this issue, you can change serverless-nextjs to use the Managed Cache Policies provided by AWS using the following:

const app = new NextJSLambdaEdge(..., {
  // Remove the "as CachePolicy" if using JavaScript
  // It's required as the nextImageCachePolicy is set to CachePolicy but CachePolicy.CACHING_DISABLED is of type ICachePolicy
  nextImageCachePolicy: CachePolicy.CACHING_DISABLED as CachePolicy,
  nextLambdaCachePolicy: CachePolicy.CACHING_DISABLED as CachePolicy,
});

Obviously, this isn't great for production apps (which mine isn't) but its another solution to the problem.

Note: I'm using "aws-cdk": "2.19.0",

james-wallis avatar Jun 23 '22 14:06 james-wallis