When deploying multiple apps via CDK I hit the cache policy limit on my account
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
- Hoist the cache policies to the top of the stacks
- Allow users to pass in their own policies
- Implement some API for
nextApp.resuseCachePolicies(otherNextApp)
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,
});
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",