Back to Blog
9 min read
Web

S3 CORS Policy Generator: Create AWS Bucket CORS JSON for Browser Uploads

Generate AWS S3 CORS policies for browser uploads, public reads, signed downloads, and presigned URLs. Learn CORSRules, AllowedOrigins, AllowedMethods, AllowedHeaders, ExposeHeaders, MaxAgeSeconds, and put-bucket-cors.

Build an S3 CORS policy for frontend uploads and reads

Use Spoold's S3/R2 CORS Generator to create an AWS S3 bucket CORS policy for browser uploads, public reads, signed downloads, and presigned URL flows. The tool produces editable policy JSON, an AWS CLI file with CORSRules, and a preflight curl for testing.

What is an S3 CORS policy?

An S3 CORS policy is a bucket-level rule set that tells Amazon S3 which browser origins can access objects, which HTTP methods are allowed, which request headers can be sent, and which response headers JavaScript can read. It is separate from IAM, bucket policies, ACLs, and presigned URL authorization.

S3 console JSON vs AWS CLI JSON

The S3 console commonly shows the rules themselves. The AWS CLI put-bucket-cors command expects a wrapper object with CORSRules. This small difference is easy to miss, so the generator outputs both.

Rule list

[
  {
    "AllowedOrigins": ["https://app.example.com"],
    "AllowedMethods": ["GET", "PUT", "HEAD"],
    "AllowedHeaders": ["Content-Type"],
    "ExposeHeaders": ["ETag"],
    "MaxAgeSeconds": 3600
  }
]

AWS CLI file

{
  "CORSRules": [
    {
      "AllowedOrigins": ["https://app.example.com"],
      "AllowedMethods": ["GET", "PUT", "HEAD"],
      "AllowedHeaders": ["Content-Type"],
      "ExposeHeaders": ["ETag"],
      "MaxAgeSeconds": 3600
    }
  ]
}

Recommended S3 CORS policies by use case

Use caseMethodsHeadersExpose
Public asset readGET, HEADUsually emptyContent-Length
Presigned PUT uploadPUT, HEADContent-Type, x-amz-*ETag
Presigned POST uploadPOST, HEADContent-Type, x-amz-*ETag
Signed downloadGET, HEADAuthorization if sentETag

How to generate an S3 CORS policy

  1. Open the S3 CORS policy generator and select AWS S3.
  2. Pick a preset for public read, presigned upload, signed download, or assets.
  3. Add exact origins such as https://app.example.com and http://localhost:3000.
  4. Add all request headers your frontend sends.
  5. Copy the policy or download the AWS CLI JSON file.
  6. Apply it with aws s3api put-bucket-cors --bucket BUCKET --cors-configuration file://cors-aws-cli.json.

Common S3 CORS mistakes

  • Using the wrong wrapper: AWS CLI expects CORSRules, not only a bare array.
  • Forgetting localhost: your production origin does not cover local dev.
  • Allowing GET but uploading with PUT: the preflight method must be allowed.
  • Missing upload headers: every header in Access-Control-Request-Headers must be covered.
  • Not exposing ETag: uploads may succeed, but JavaScript cannot read ETag unless it is in ExposeHeaders.

Use the debugger for failed preflight requests

Paste your current S3 CORS policy into the S3/R2 CORS debugger, then enter the browser origin, method, request headers, and console error. The debugger shows whether the request fails because of origin, method, request headers, exposed response headers, or wildcard origin with credentials.

Try It Now

Put this guide into practice with our free tools. No sign-up required.

Generate S3 CORS Policy
S3 CORS Policy Generator: Create AWS Bucket CORS JSON for Browser Uploads | Spoold Blog | Spoold