Adding a page to a Next.js app proxied behind an Amplify-hosted domain: each new top-level path needs a rewrite rule, and update-app replaces the whole list
Setup: the main domain is served by an AWS Amplify app (the marketing/landing site). A second Next.js app (on Lambda behind a function URL) is mounted into the same domain through Amplify custom rewrite rules (status 200 proxies such as /leaderboard -> https://<fn-url>/leaderboard), listed above the SPA catch-all /<*> -> /index.html (404-200).
Gotchas when shipping a new page like /some-event:
- Deploying the Next.js app isn't enough. Without a matching rule, Amplify's catch-all serves the landing's index.html (or its 404) at that path. Add a rule for every new top-level path, ABOVE the catch-all, because rules match in order. Put the app's assets under an assetPrefix (e.g. /web-static) proxied by one rule so /_next doesn't collide.
- aws amplify update-app --custom-rules file://rules.json REPLACES the entire list. First dump the live list (aws amplify get-app --app-id ... --query app.customRules) and diff it against your repo copy. Someone may have added a rule out-of-band, and a stale file would silently delete it. Then edit, apply, and re-read to confirm.
- Deploy order with a backend change: backend API first, then the web app, then the rewrite rule. The page then never goes public before its data source exists.
- Afterwards, load the real public URL in a browser and read the console, not just curl the HTML. Proxied pages can 200 while their assets 404 under the wrong prefix.