My use case is simple, I have static files (JS, images) in S3 that I want to share to multiple origins via CloudFront CDN.
I only want to publicly allow GET
from S3 and my actual configuration is the following:
<CORSRule>
<ID>BucketCORSRules</ID>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>HEAD</AllowedMethod>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3600</MaxAgeSeconds>
</CORSRule>
Everything works nicely except that sometimes I randomly get a "no 'Access-Control-Allow-Origin' header is present"
error when I put new S3 objects.
My question is about AllowedHeader
.
I've read everywhere (here on SO, again on SO and here on AWS) that AllowedHeader
should be set to *
or Authorization
, but why?
Shouldn't this CORS configuration be working with CORS simple requests without any AllowedHeader
? What could possibly drive to random "no 'Access-Control-Allow-Origin' header is present"
errors?
The
AllowedHeader
element specifies which headers are allowed in a preflight request through theAccess-Control-Request-Headers
header. Each header name in theAccess-Control-Request-Headers
header must match a corresponding entry in the rule. Amazon S3 will send only the allowed headers in a response that were requested. For a sample list of headers that can be used in requests to Amazon S3, go to Common Request Headers in the Amazon Simple Storage Service API Reference guide.
Source: http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html#cors-allowed-headers