RJPearson94 / terraform-aws-open-next

Terraform Module for Open Next
https://registry.terraform.io/modules/RJPearson94/open-next/aws/latest
Apache License 2.0
76 stars 11 forks source link

How does revalidation work? #25

Open Saba-Shavidze opened 7 months ago

Saba-Shavidze commented 7 months ago

Question

How can I run revalidation for server function, to get the new products from the endpoint? I run invalidation of/* from console from cloudfront but does not work. For future, I want to implement the scenario where It could be possible to run revalidation from the admin application.

RJPearson94 commented 7 months ago

hi @Saba-Shavidze,

Just to check, do you want to run Cloudfront invalidation from the server function?

I am a little confused by "I run invalidation of /* from console from cloudfront but does not work." as it does take time for the invalidation to propagate but it does invalidate the distribution, so not sure how this didn't work. can you provide some more context how this didn't work

Saba-Shavidze commented 7 months ago

@RJPearson94 For better clarification I will explain my problem. I have strapi for content management, let assume that I added some new products and want to update the cache, I trigger the webhook from strapi which make a post request to the api which is handled by the server function, but is it enough? Or do I need to throw the event to sqs-revalidation queue?

RJPearson94 commented 7 months ago

hi @Saba-Shavidze, I think it will depend on how you've built the website, i.e., whether you use ISR or not, but I would say you should call CloudFront and invalidate the cache on either the root '/' or on a specific path. This should allow the new content to be fetched (and cached) in CloudFront. I don't see a need for you to put anything on the queue

shavidze commented 7 months ago

@RJPearson94 What is the purpose of the revalidation queue, I was thinking I need to add something there and then revalidate the api cache, otherwise yes I'm updating the cloudfront cache.

RJPearson94 commented 7 months ago

The open next docs provide more context on ISR and how it works in open next. The troubleshooting guide provides additional context too https://open-next.js.org/v2/inner_workings/isr https://open-next.js.org/v2/common_issues/isr

shavidze commented 7 months ago

So, on demand validation should be done from the code on nextjs side