- Newest
- Most votes
- Most comments
One possible reason is that the object was cached in South Africa's CloudFront PoP before you added the CORS related headers in your origin (S3).
If you added the CORS header after the object was already cached by CloudFront it will not be automatically propagated and you need to manually invalidate the cache entry (or wait for the object to expire).
e.g.,
aws cloudfront create-invalidation --distribution-id YOUR_DISTRIBUTION_ID --paths /main-E2LOABSB.js
Thanks for pointing me in the right direction that every CloudFront edge location has its own cache and could cache the response differently.
Upon invalidation, and attempting to get the file from UK client without adding -H "Origin: https://origin.com
to the cURL request, I realized that the file got cached in the edge closest to me without the CORS headers. There was no way to fix this issue until I re-invalidate. Thus, I realised that the original file main-E2LOABSB.js
could've been requested by a non-browser in South Africa before it was requested by a browser, which caused the CORS headers to be missing for that file.
Upon this, I checked the Behaviour settings for my CloudFront distribution, and I realized that I am still using legacy settings since I first set up the distribution when the current new settings did not exist.
I modified my legacy settings to a custom cache policy, and to use Managed-CORS-S3Origin with Managed-CORS-with-preflight-and-SecurityHeadersPolicy.
Now after invalidating the file, when Origin header is present, the CORS headers show. If the Origin header is not present, the CORS headers do not show. All disregarding to order of which request was first. This resolves my problem.
Relevant content
- asked a year ago
- asked 7 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 3 years ago