Did you know?
The AWS CLI rejects the S3 CORS JSON from the console unless you wrap it in "CORSRules".
Wrap S3 CORS rules in {"CORSRules": [...]} for aws s3api put-bucket-cors.
- DevOps & cloud
- Last checked
Explained
The S3 console’s CORS editor takes a plain JSON array of rules. aws s3api put-bucket-cors doesn’t: paste the same array into a file and it fails with Error parsing parameter ‘–cors-configuration’: Invalid JSON. Wrap the rules in an object:
{
"CORSRules": [
{
"AllowedOrigins": ["https://app.example.com"],
"AllowedMethods": ["GET", "HEAD"],
"AllowedHeaders": ["*"],
"MaxAgeSeconds": 3600
}
]
}
aws s3api put-bucket-cors --bucket my-assets --cors-configuration file://cors.json
Also remember that put-bucket-cors replaces the whole configuration, so include every rule you want to keep. We checked both behaviors with AWS CLI 2.34.
Learn more
- How to Configure CORS in Amazon S3 Buckets (Console, CLI and Terraform) Full guide · Updated Dec 2026
