aws-amplify / aws-amplify/amplify-hosting

Allow filtering query params for cloudfront policy or custom cloudfront policy

Open
#4,041 2 comments 0 reactions 0 assignees View on GitHub
feature-request hosting
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Environment information

```plain text
N/A? Site is frontend SSG/SSR only with nextjs and no backends/amplify SDK used in the code.
```

### Describe the feature

The managed cloudfront policies allow removing cookies from the cloudfront cache key. It would be useful to also be able to either completely ignore query params or ignore specific query params like you can with a custom cloudfront policy.

Alternatively allowing a completely custom cloudfront policy to be used would allow this setup.

### Use case

With next.js (currently using v14), the default behavior is to prefetch links between pages when the link element is in the browser viewport. These requests have a `_rsc` query param added with a random token for the prefetch.

We have a docs site which doesn't have any query params except for the prefetch params on pages. The problem is all of the prefetches cache miss on cloudfront even if the page exists in cloudfront because of the query parameter. I think this would be solved by ignoring the `_rsc` query param in the cloudfront policy for the cache key.

We haven't been running the deployment long enough to see, but so far it seems like most of the pages don't benefit from caching (we're setting to 20 minutes with stale-while-revalidate) with the cookies disabled cache policy.

It is possible to disable prefetching as a workaround (although not at a global level in nextjs unfortunately), it just results in a slightly degraded user experience for page navigation.

Contributor guide

Open the contributing guide

Research direction

No files, tests, or entry points are named in the issue. Start by locating how Amplify Hosting exposes managed and custom CloudFront policies, then compare the requested query-parameter behavior with the Next.js `_rsc` use case. Done means the supported policy configuration can ignore all or selected query parameters, with coverage for the resulting cache behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, nextjs
Domain
cloud, performance
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.