-
Notifications
You must be signed in to change notification settings - Fork 46
Docs for aws 3.4 #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Docs for aws 3.4 #51
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import {Callout} from 'nextra/components' | ||
|
|
||
| Available since `@opennextjs/aws` 3.4.0 | ||
|
|
||
| This override is used by OpenNext when routes have been On-Demand revalidated and the CDN needs to be updated. It is not called for ISR revalidation. | ||
| It will be called for `revalidatePath`, `revalidateTag` and `res.revalidate()`. | ||
|
|
||
| If you want to better understand how to implement your own Automatic CDN Invalidation, the easiest way would be to take a look at the existing [included Automatic CDN Invalidation](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/cdnInvalidation) | ||
|
|
||
| ## Included Automatic CDN Invalidation | ||
|
|
||
| ### dummy | ||
|
|
||
| The Dummy AutomaticCDNInvalidation is a dummy implementation that will do nothing. It is the default implementation. | ||
|
|
||
| ### cloudfront | ||
|
|
||
| <Callout type='warning'> | ||
| Cloudfront invalidation can be very expensive. Manual CloudFront path invalidation incurs costs. According to the [AWS CloudFront pricing page](https://aws.amazon.com/cloudfront/pricing/): | ||
|
|
||
| > No additional charge for the first 1,000 paths requested for invalidation each month. Thereafter, $0.005 per path requested for invalidation. | ||
| This implementation will request 2 path invalidation requests for every route that needs to be invalidated (one for the route itself and one for the data route). | ||
|
|
||
| Tag cache invalidation could end up triggering thousands of invalidation requests. | ||
|
|
||
| Only use this implementation if you are aware of the costs and are willing to pay for it. | ||
| </Callout> | ||
|
|
||
| The CloudFront Automatic CDN Invalidation will invalidate the cache of the CloudFront distribution. | ||
|
|
||
| ##### Requirements | ||
|
|
||
| - You need to provide the `CLOUDFRONT_DISTRIBUTION_ID` environment variable to your server. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,71 @@ | ||
| import { Callout } from 'nextra/components'; | ||
|
|
||
| This override is used by the [`cache` adapter](https://github.com/opennextjs/opennextjs-aws/blob/main/packages/open-next/src/adapters/cache.ts) that is provided by OpenNext to the NextServer. It is also used by OpenNext if `enableCacheInterception` is set to `true` in the configuration. | ||
|
|
||
| It is used for retrieving and updating the ISR/SSG cache as well as the fetch cache used by Next.js. It does not handle anything related to cache tags (i.e. `revalidateTag` and `revalidatePath`) | ||
|
|
||
| If you want to better understand how to implement your own IncrementalCache, the easiest way would be to take a look at the existing [included IncrementalCache](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/incrementalCache). | ||
|
|
||
| One thing to note is that it is not used at build time, only at runtime. This means that you'll have to upload the cache yourself if you want to use the prebuilt routes/pages (And this is mandatory for ISR/SSG routes with `fallback:false`). | ||
| All the cache files are present in the `.open-next/cache` folder. The one under `BUILD_ID` are for the ISR/SSG cache and the one under `__fetch/BUILD_ID` are for the fetch cache. | ||
| All the cache files are present in the `.open-next/cache` folder. The one under `BUILD_ID` are for the ISR/SSG cache and the one under `__fetch/BUILD_ID` are for the fetch cache. | ||
|
|
||
| ## Included IncrementalCache | ||
|
|
||
| ### s3 | ||
|
|
||
| The S3 IncrementalCache will store fetch and ISR/SSG cache in an S3 bucket. It is used by default if you don't provide any IncrementalCache in your configuration. | ||
| It uses the `@aws-sdk/client-s3` to interact with S3. | ||
|
|
||
| ##### Requirements | ||
|
|
||
| - You need to provide the `CACHE_BUCKET_REGION`, `CACHE_BUCKET_KEY_PREFIX`, `CACHE_BUCKET_NAME` environment variables to your server. | ||
|
|
||
| ### s3-lite | ||
|
|
||
| The S3Lite IncrementalCache will store fetch and ISR/SSG cache in an S3 bucket | ||
| This implementation is a lighter version of the `s3` IncrementalCache as it uses `aws4fetch` to interact with S3. | ||
|
|
||
| ##### Requirements | ||
|
|
||
| - You need to provide the `CACHE_BUCKET_REGION`, `CACHE_BUCKET_KEY_PREFIX`, `CACHE_BUCKET_NAME`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` environment variables to your server. | ||
|
|
||
| ### dummy | ||
|
|
||
| The Dummy IncrementalCache is a dummy implementation that throws exceptions for every method. It should not be used unless you want to disable the cache. | ||
|
|
||
| ### fs-dev | ||
|
|
||
| The FsDev IncrementalCache is a simple implementation that stores the cache in the `.open-next/cache` folder and interact with it using the filesystem. It is useful for development purposes only. | ||
|
|
||
| ##### Requirements | ||
|
|
||
| It needs to run on the local filesystem, and expect to be run from the OpenNext output. | ||
|
|
||
| ### multi-tier-ddb-s3 | ||
|
|
||
| <Callout type='warning'> | ||
| Because of how it works, this implementation is only eventually consistent and errors during update could cause inconsistencies between the local cache in some instances and the S3 cache. | ||
|
|
||
| It could also end up being slower (and more expensive) than simpler implementations if used in a low traffic serverless environment. | ||
| </Callout> | ||
|
|
||
| The MultiTierDdbS3 IncrementalCache is a more complex implementation. | ||
| Cache are stored in a local In Memory LRU cache as well as in S3. DynamoDB is used to keep local cache in sync between multiple instances of the server. | ||
| It uses `aws4fetch` to interact with S3 and DynamoDB. | ||
|
|
||
| ##### How does it work | ||
|
|
||
| On get : | ||
| 1. When a cache is requested, it first checks the local cache. If the cache is not found, it will fetch it from S3 and store it in the local cache. | ||
| 2. If the local cache exist for this key, it will check metadata in DynamoDB to see if the cache is still valid. If it is not, it will fetch the cache from S3 and store it in the local cache. | ||
| 3. If the local cache is valid, it will return it. | ||
|
|
||
| On update : | ||
| 1. When a cache is updated, it will first try to update the cache in S3. | ||
| 2. If the update is successful, it will update the metadata in DynamoDB. | ||
| 3. Finally, it will update the local cache. | ||
|
|
||
| ##### Requirements | ||
|
|
||
| - You need to provide the `CACHE_BUCKET_REGION`, `CACHE_BUCKET_KEY_PREFIX`, `CACHE_BUCKET_NAME`, `CACHE_DYNAMO_TABLE`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN`, `OPEN_NEXT_LOCAL_CACHE_TTL_MS` (optional), `OPEN_NEXT_LOCAL_CACHE_SIZE`(optional) environment variables to your server. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. idea for later: provide a table of of env vars detailing where they are used and if mandatory
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Definitely, we could probably have a |
||
| - DynamoDB table should have a primary key `path` of type `String` and a sort key `tag` of type `String`. (It can reuse the same table as the one used by the default `tagCache`) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,42 @@ | ||
| import {Callout} from 'nextra/components' | ||
|
|
||
| This override is used by OpenNext to trigger the revalidation of stale routes. | ||
| Before sending the response to the client, OpenNext will check if the route is stale and if it is, it will call the queue override to revalidate the route. | ||
|
|
||
| If you want to better understand how to implement your own Queue, the easiest way would be to take a look at the existing [included Queue](https://github.com/opennextjs/opennextjs-aws/tree/main/packages/open-next/src/overrides/queue). | ||
|
|
||
| Couple of things to note : | ||
| - The default implementation use an SQS queue. This has the main advantage of being able to control the concurrency of the revalidations as well as avoiding trigerring the revalidation multiple times for the same route. | ||
| - You don't have to use a queue at all. You could trigger the revalidation directly in the Queue override itself. You can see a very simple implementation of this [in the `queue` override](/aws/contribute/local_run#devqueuets). | ||
| - You don't have to use a queue at all. You could trigger the revalidation directly in the Queue override itself. You can see a very simple implementation of this [in the `queue` override](/aws/contribute/local_run#devqueuets). | ||
|
|
||
| ## Included Queue | ||
|
|
||
| ### sqs | ||
|
|
||
| The SQS Queue will send a message to an SQS queue for each route that needs to be revalidated. It is used by default if you don't provide any Queue in your configuration. | ||
| It uses the `@aws-sdk/client-sqs` to interact with SQS. | ||
|
|
||
| #### Requirements | ||
|
|
||
| - You need to provide the `QUEUE_URL` environment variable to your server. | ||
|
|
||
| ### sqs-lite | ||
|
|
||
| The SQSLite Queue will send a message to an SQS queue for each route that needs to be revalidated. | ||
| This implementation is a lighter version of the `sqs` Queue as it uses `aws4fetch` to interact with SQS. | ||
|
|
||
| #### Requirements | ||
|
|
||
| - You need to provide the `QUEUE_URL`, `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` and `AWS_SESSION_TOKEN` environment variables to your server. | ||
|
|
||
| ### direct | ||
|
|
||
| The Direct Queue will directly trigger the revalidation of the route in the Queue override itself. It is useful for development purposes and when you don't want to use a queue. | ||
|
|
||
| <Callout type='warning'> | ||
| Be careful with this implementation as it could lead to multiple revalidations of the same route. | ||
| </Callout> | ||
|
|
||
| ### dummy | ||
|
|
||
| The Dummy Queue is a dummy implementation that will throw an exception. It should not be used unless you want to disable ISR. |
Uh oh!
There was an error while loading. Please reload this page.