-
-
Notifications
You must be signed in to change notification settings - Fork 451
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
Support on-demand purge nextjs cache released in 12.1 #2417
Comments
I am trying this function on my website (using next 12.1, sls-nextjs-component) and it return error 500. Can you confirm that it is not currently supported? ...and that I am not the problem? |
This is the error I get when I tried to call
|
same response here! |
would be nice to have it? what other ways to consider? maybe calling revalidation lambda manually? |
Very new to Serverless Next.js but it seems like a lot of the groundwork for this has been completed in #1028. So perhaps all that's required is another Lambda function that can be called with a secret token along with a path, which would then trigger a message in the SQS queue for the Next.js Regeneration Lambda to handle. (No doubt easier said than done!) Or seeing as our use-case for this would be on-demand from a CMS, we could manufacturer a SQS message from that CMS, although it seems like the Regenerate Lambda is expecting a CloudFront request object, which is not ideal to have to manufacture! |
I was able to trigger regeneration. Feel free to adapt this code to your needs until we get some better official approach. import { triggerStaticRegeneration } from '@sls-next/lambda-at-edge/dist/lib/triggerStaticRegeneration'
import { defaultRegion, siteSQS, websiteBucket } from '../../config'
import * as s3 from './s3'
export async function getBuildId(): Promise<string> {
const x = await s3.get('BUILD_ID', websiteBucket)
return (x || '').toString()
}
export function getPageKey(buildId: string, key: string) {
return `${getStaticPagesPath(buildId)}/${key}.html`
}
export function getStaticPagesPath(buildId: string) {
return `static-pages/${buildId}`
}
export function getRegenerationOptions({
queueName,
buildId,
page,
lang,
bucket,
region,
counter
}: {
queueName: string
buildId: string
page: string
lang: 'en' | 'ka'
bucket: string
region: string
counter: number
}) {
return {
basePath: '',
pagePath: 'pages/' + (page || 'index') + '.js',
pageS3Path: '/' + lang + (page ? '/' + page : '') + '.html',
storeName: bucket,
storeRegion: region,
request: {
uri: '/' + lang + (page ? '/' + page : ''),
origin: {
s3: {
region,
domainName: `${bucket}.s3.${region}.amazonaws.com`,
path: '/' + getStaticPagesPath(buildId)
}
}
} as AWSLambda.CloudFrontRequest,
eTag: Date.now() - 1000 + counter,
lastModified: Date.now() - 1000 + counter,
queueName
}
}
export async function regeneratePage(lang: 'en' | 'ka', page: string, counter = 0) {
const buildId = await getBuildId()
console.log('queue', siteSQS)
const options = getRegenerationOptions({
queueName: siteSQS,
buildId,
lang,
page,
bucket: websiteBucket,
region: defaultRegion,
counter
})
console.log(options)
const x = await triggerStaticRegeneration(options as any)
console.log('event', x)
}
|
Wow, thanks for the quick response @kigorw. |
Hi, thank you so much for having This is my prototype: https://d2flbk08lhbnjs.cloudfront.net |
@kigorw hi, could you explain more about the implementation of your code? Thanks! |
@m0rph3u5-zip I make a call from my separate serverless lambda function. @RodrigoTomeES I reused |
@kigorw Hi thanks, and how I can deploy the lambda to work with serverless-next? I mean, once it's deployed, I'll have to call it every time, for example, a product is saved in Wordpress, right? But how I can deploy the lambda in AWS to work with the serverless-next bucket? |
Hello guys, I'm going through this deployment problem on aws |
Still getting the same error: "Invariant: required internal revalidate method not passed to api-utils" when trying to call |
@sitezen any luck? I'm facing the same issue and have not found any solution. |
@AlejandroJAguilarP I'd like to have Lambda function which will trigger on DynamoDB events and will run revalidation of specified page. Code above requires to add too huge package to Lambda function to call of |
Thanks a lot @kigorw, it works. For anyone who implements this, make sure you have at least an ISR page (with revalidate property returned by getStaticProps) not only SSG pages, otherwise the regenerate lambda (with the latest build manifest) won't be deployed, as a result, the regeneration won't work as expected, either no regeneration lambda will be created or if you had deployed previously with bundle contain ISR page and now you deploy it without it, the regeneration lambda will not be updated with the latest manifest thus it will pick the previous buildID and not the latest one, even though you provide correct static path with latest buildID. |
Any idea if this is being planned for a future release? According to this blog entry (from April 2022) Serverless Cloud already supports On-Demand ISR. Has it simply not been added to serverless-nextjs yet? |
Is your feature request related to a problem? Please describe.
Without the mechanism to purge the nextjs cache, it is a pitfall in production use and causing a lot of problems.
Describe the solution you'd like
Support the
res.unstable_revalidate
in api which can be controlled by backend to purge the cache and regenerate the page requested. It is supported in Nextjs 12.1, and it will be great if we can support it as well:https://nextjs.org/blog/next-12-1
Describe alternatives you've considered
Disable the next.js cache totally. To be tested. Using CDN Cache instead with a purge api call.
Additional context
An example is in this video:
https://www.youtube.com/watch?v=BGexHR1tuOA&t=16s
The text was updated successfully, but these errors were encountered: