I'm trying to apply a CORS policy to my S3 bucket, and what I am observing is that, if at any point of time, I modify the CORS policy, the older files that were uploaded to S3 still do not use the new CORS policy. For e.g.
- I created a S3 bucket "X"
Added the following CORS policy -
<CORSConfiguration> <CORSRule> <AllowedOrigin>https://app1.example.com</AllowedOrigin> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>DELETE</AllowedMethod> <ExposeHeader>ETag</ExposeHeader> <ExposeHeader>x-amz-meta-custom-header</ExposeHeader> <AllowedHeader>*</AllowedHeader> </CORSRule> </CORSConfiguration>
Successfully uploaded a file a.jpeg from my application that is hosted on
https://app1.example.com
. I was also able to do a GET and a DELETE.Now I need to use the same S3 bucket for another one of my hosted apps, say app2. So I modified the CORS policy to -
<CORSConfiguration> <CORSRule> <AllowedOrigin>https://app1.example.com</AllowedOrigin> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>DELETE</AllowedMethod> <ExposeHeader>ETag</ExposeHeader> <ExposeHeader>x-amz-meta-custom-header</ExposeHeader> <AllowedHeader>*</AllowedHeader> </CORSRule> <CORSRule> <AllowedOrigin>https://app2.example.com</AllowedOrigin> <AllowedMethod>POST</AllowedMethod> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>DELETE</AllowedMethod> <ExposeHeader>ETag</ExposeHeader> <ExposeHeader>x-amz-meta-custom-header</ExposeHeader> <AllowedHeader>*</AllowedHeader> </CORSRule> </CORSConfiguration>
Now when I try to GET the file a.jpeg from
https://app2.example.com
, I still see the below errorXMLHttpRequest cannot load <S3 URL>. Origin https://app2.mydomain.com is not allowed by Access-Control-Allow-Origin.
However if I try to upload a new file b.jpeg from
https://app2.mydomain.com
, everything works as expected.
EDIT
I forgot to mention this earlier, but we have a CloudFront CDN in front of our S3 bucket, but I cannot find any config related to setting CORS policy in the Cloudfront config.
Is there a way by which we can enforce the new CORS policy on previously uploaded files as well? Or is there some other way to make this work?
`
backticks, with an edit, please. That should cause them to be interpreted as opaque string literals instead of links. Also "example.com" is preferred, since I assume the domain you've used isn't your actual domain, and may be somebody else's. – Depth*.example.com
)... but is it possible your browser cached the preflight response from before the change was made? Can you capture the response headers S3 is actually returning? – DepthOrigin:
and the other two headers to S3. – Depth