- Newest
- Most votes
- Most comments
Hi Jess,
I believe that the response header policy is executed on the viewer response, which means this execution happens after the edge has served the object. As such, you can set a max-age value for the client, but I don't believe you can set an s-maxage in the viewer response stage. The documentation here specifically calls out setting a cache-control response header to control browser caching.
There are a few options to get around this. Note that I am assuming that you are not setting a cache-control header at the origin. I am also assuming that you have a cache behavior specifically for /index.html.
- In the cache policy for this specific cache behavior, set the default and max TTL's to 31536000. This should instruct the edge to cache for 31536000 seconds. In your response header policy, use your existing rule, just remove the s-maxage value. This should give you the result you are looking for, where the object is cached on the edge for desired TTL, but not cached in the browser.
- A second option is to use a Lambda@Edge function in the origin response stage. You are able to set both the max-age and s-maxage in the origin response stage since this stage executes before the edge serves the object. To the edge, it appears that a cache-control header is being set by the origin. Here is a sample function that you could use as a reference. Please note that in this scenario you still need to make sure that your cache policy min and max TTL values are wide enough to accommodate any cache-control values that you might be setting. For example, if you are defining a cache-control value of 300 in your Lambda@Edge function, then your cache policy max TTL must be at least 300 as well.
My personal recommendation is to use option 1, since you are defining this only for a single index.html file. If you have a requirement to define a large number of cache-control headers for different URI's, then the Lambda@Edge function is likely the better option. Just be aware that there is a cost for those function invocations.
PS, it looks like you might also have a typo in your origin override as well.
Relevant content
- asked 2 years ago
- asked a year ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 7 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago