-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Using EFS as cache for data cache, full route cache, and image optimization cache means we must use NAT Gateway to access internet for Nextjs*Functions
whereas if we used S3, NAT Gateways would not be required. By default, NAT Gateways cost $65/mo for 2 AZs which is cost prohibitive for some customers. Nextjs*Containers
constructs already require VPC and NAT Gateway to access internet so it cannot be avoided for those constructs.
Should we do this?
To do so, we'd need to update src/nextjs-build/cdk-nextjs-cache-handler.ts to handle data cache and full route cache updates to S3 instead of EFS. How to update image optimization cache? Types on exported IncrementalCacheValue
type from Next.js (next/dist/server/response-cache) seems to indicate images are set
in the custom cache handler but are they fetched? Would we need to provide a custom next.config.js#images.loaderFile? I'd prefer to use Next.js' default sharp image optimization. Shouldn't be too complicated.
We'd also need to account for revalidateTag
and keep track of when they expire. We could use DynamoDB for this or try to just use S3 metadata? Lifecycle policies fastest expiration time in 1 day, but that's fine - we could check to see if it expired before returning in set
function.
Resources:
- https://github.com/opennextjs/opennextjs-aws/blob/de77cff8ec74123af5a1ed58fc120c5e360621e0/packages/open-next/src/overrides/incrementalCache/multi-tier-ddb-s3.ts
- Add example for AWS S3 caching-tools/next-shared-cache#123 (comment)
@chxlloyd , @coltenkrauter, @gbone-restore, @LaurenceGA, @mohsen1, curious about your opinions on this. Please chime in if you have any thoughts. Thank you!