Interview Prep/AWS/S3, EBS and EFS

A browser upload to S3 fails: `has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource`.

IntermediateTroubleshootingS3, EBS and EFS
Answer

Likely causes → The bucket has no CORS configuration, or it does not list the origin, method (PUT/POST) or headers the browser sends in the preflight. Presigned PUTs with custom headers such as Content-Type need AllowedHeaders.

Diagnose →

aws s3api get-bucket-cors --bucket uploads
curl -i -X OPTIONS "https://uploads.s3.amazonaws.com/test.txt" \
  -H 'Origin: https://app.example.com' -H 'Access-Control-Request-Method: PUT'

Fix →

aws s3api put-bucket-cors --bucket uploads --cors-configuration '{
 "CORSRules":[{"AllowedOrigins":["https://app.example.com"],"AllowedMethods":["PUT","GET"],
 "AllowedHeaders":["*"],"ExposeHeaders":["ETag"],"MaxAgeSeconds":3000}]}'

If CloudFront is in front, forward the Origin header in the origin request policy.

Prevent → Keep the CORS config in IaC with explicit origins per environment. Never use * together with credentials.

aws All AWS questions Roadmap: AWS core services

More on S3, EBS and EFS