Generate CORS configurations for AWS S3 buckets
CORS Configuration Tips
{
"CORSRules": [
{
"AllowedOrigins": [
"*"
],
"AllowedMethods": [
"GET",
"POST"
],
"AllowedHeaders": [
"*"
],
"MaxAgeSeconds": 3000
}
]
}
# Save the CORS configuration to a file first
echo '{
"CORSRules": [
{
"AllowedOrigins": [
"*"
],
"AllowedMethods": [
"GET",
"POST"
],
"AllowedHeaders": [
"*"
],
"MaxAgeSeconds": 3000
}
]
}' > cors-config.json
# Apply the CORS configuration to your S3 bucket
aws s3api put-bucket-cors --bucket YOUR_BUCKET_NAME --cors-configuration file://cors-config.json
Go to S3 → Your Bucket → Permissions → Cross-origin resource sharing (CORS) → Edit → Paste the JSON configuration
Use the provided CLI command after saving the JSON to a file
Use the aws_s3_bucket_cors_configuration resource with the generated JSON