title: How to serve AWS S3 file with Access-Control-Allow-Origin: * header
body: <p>I have a JS file in S3, which gets picked up by Cloudflare CDN, before it finally gets served on the front end. Now some of the end users have CORS error. So I want to add the <code>Access-Control-Allow-Origin: *</code> to this file. As far as I am aware, cloudflare will automatically pass the headers it is getting, so I am trying to figure out a way to add the header while it gets picked from S3.</p>
  <p><a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/cors.html#how-do-i-enable-cors" rel="nofollow noreferrer">https://docs.aws.amazon.com/AmazonS3/latest/userguide/cors.html#how-do-i-enable-cors</a></p>
  <p>Found this guide, but I am not exactly sure how to use the JSON in it.</p>
  <pre><code>[
      {
          &quot;AllowedHeaders&quot;: [
              &quot;*&quot;
          ],
          &quot;AllowedMethods&quot;: [
              &quot;GET&quot;
          ],
          &quot;AllowedOrigins&quot;: [
              &quot;http://mydoman.com&quot;
          ],
          &quot;MaxAgeSeconds&quot;: 3000
      }
  ]
  </code></pre>
  <p>Does this look right? Has anyone ever added custom headers like this while serving files from s3? Can someone suggest the correct JSON? Or something else that is needed with it?</p>