terraform-aws-next-js
terraform-aws-next-js copied to clipboard
Cloudfront lambda page issues
Hello, I've been getting some inconsistent deployments of my app. I'm not sure if there's some invalidation issue going on w/ the Cloudfront distributions or not.
After I deploy my app w/ terraform apply
, requests to lambda pages after the initial load returns 404
eg: navigating to /page/file
x-cache: Error from cloudfront
/_next/data/<SHA>/
After it 404s, the app reloads/rerenders the app, but that isn't ideal. After redeploying several times, I get lucky and the requests to the pages returns 200.
Any ideas what's going on? Thanks in advance.
Hi,
yes we see similar issues for /_next/data/*
routes on our own site too: https://milli.is
Normally the /_next/data/*
routes are created on the fly by Lambda, in our case it tries to request files that are only available on build time which results in an error.
It's possibly related to the missing ISR support of the module I guess. Need to take a look after I finished the transition to the server target.
The *.json
resource appears to become available several minutes (5-10 minutes? I didn't keep track).
When adding a new page, it sporadically becomes available and unavailable (404) for at least 2 hours. My page is now stable.
For the success scenario, is the request hitting a new lambda container? And likewise, for the 404, could it be hitting the older container?
I have a EventBridge that pings the app every 5 minutes and keeping the older container alive. Perhaps that's what is causing the issue?
Hi, yes we see similar issues for
/_next/data/*
routes on our own site too: https://milli.is Normally the/_next/data/*
routes are created on the fly by Lambda, in our case it tries to request files that are only available on build time which results in an error.It's possibly related to the missing ISR support of the module I guess. Need to take a look after I finished the transition to the server target.
Hello, any recommendations for a quick fix I can make to prevent the /_next/data/*
errors? Seeing something similar on my site, not sure how to address it. What I've done for now is disable the page lambda, but I'll admit I'm not entirely sure what side effects that may have. As far as I can tell, my site functions fine without it though.
Hey @wpniederer, looking into the Cloudwatch logs for this Lambda would be a good start. In our case a file (The MDX source for the blog post) that is required at build time but not available at runtime causes the issue.