Generate CORS configurations for AWS S3 buckets
CORS Configuration Tips
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"POST",
"GET",
"PUT",
"HEAD",
"DELETE"
],
"AllowedOrigins": [
"https://cdn.sanjaysikdar.dev",
"https://sanjaysikdar.dev"
],
"ExposeHeaders": [
"ETag"
]
}
]# Save the CORS configuration to a file first
echo '[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"POST",
"GET",
"PUT",
"HEAD",
"DELETE"
],
"AllowedOrigins": [
"https://cdn.sanjaysikdar.dev",
"https://sanjaysikdar.dev"
],
"ExposeHeaders": [
"ETag"
]
}
]' > 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.jsonGo 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