- Newest
- Most votes
- Most comments
This issue appears to be related to how your CORS configuration is being applied to the S3 buckets. The 500 error in the preflight request suggests a server-side issue rather than a simple CORS misconfiguration.
Here are a few things to check:
-
Verify that the CORS configuration has been properly applied to your local environment bucket. You can use the AWS CLI command
aws s3api get-bucket-cors --bucket your-bucket-nameto confirm the current CORS settings. -
Make sure your CORS configuration is properly formatted. The configuration you've shared looks correct, but sometimes there can be subtle issues. For example, ensure there are no trailing commas or syntax errors.
-
Consider simplifying your CORS configuration for testing purposes. You could try using a wildcard for origins temporarily:
{
"AllowedHeaders": ["*"],
"AllowedMethods": ["GET", "PUT", "POST"],
"AllowedOrigins": ["*"]
}
-
Check if there are any bucket policies or IAM permissions that might be interfering with the CORS settings on your local environment bucket.
-
Ensure that the S3 bucket for the local environment is properly configured to handle the presigned URLs. The 500 error could indicate an issue with how the bucket processes the request.
If the issue persists after these checks, it might be worth recreating the CORS configuration from scratch for the problematic bucket, as sometimes configuration changes don't apply correctly.
Sources
Enable email for your Amazon Connect instance - Amazon Connect
GetBucketCors - Amazon Simple Storage Service
Amazon S3 examples using AWS CLI - AWS SDK Code Examples
Thanks guys, I didn't touch it since I created this question and now it just works. I assume it has been a bug or a delay on AWS side. My advice to anyone having the same issue (CORS error with status 500) is unfortunately to just wait. I don't know when it started to work but I wasted a couple of hours trying to make it work.
The Real Cause (Likely): Your local bucket’s CORS config is not actually applied or active — despite appearing correct in the AWS CLI or console.
Reapply the CORS configuration using the AWS CLI, even if it looks correct.
aws s3api put-bucket-cors --bucket your-local-bucket --cors-configuration file://cors.json
Your cors.json should look like this: { "CORSRules": [ { "AllowedHeaders": ["*"], "AllowedMethods": ["GET", "PUT", "POST"], "AllowedOrigins": [ "http://localhost:8000", "http://192.168.50.106:8000" ] } ] }
S3 has no versioning or validation for CORS configs, it’s possible for it to look correct but not actually apply until you explicitly re-save it.
Also double-check: The bucket region matches what your backend uses to generate pre-signed URLs. A mismatch there can break preflight requests.
aws s3api get-bucket-location --bucket your-local-bucket
Run a quick OPTIONS test with curl to validate CORS preflight responses:
curl -i -X OPTIONS https://your-bucket.s3.<region>.amazonaws.com/your-key
-H "Origin: http://localhost:8000"
-H "Access-Control-Request-Method: PUT"
If you don’t see a proper Access-Control-Allow-Origin in the response, the config isn’t active and reapplying it usually fixes it immediately.
Since you are getting error with status code 500, I think the issue is not with CORS setting but with something else. Do you have other processing before reaching the S3 bucket?
Are both the buckets and your application in the same AWS region? Can you try generating a presigned URL with a longer expiration time to rule out timeout issues.
I kind of agree with Shajam answer.
What I do know is you may need to add OPTIONS to your cors policy for preflight checks.
Relevant content
- AWS OFFICIALUpdated 4 days ago
