- Newest
- Most votes
- Most comments
Hello.
I have seen similar errors in the past, but in that case, the error occurred when the S3 region and the region used by the Boto3 client did not match.
Are you making the request in the correct region?
https://stackoverflow.com/questions/63461863/response-to-preflight-request-doesnt-pass-access-control-check-no-access-cont
The CORS (Cross-Origin Resource Sharing) policy you've configured for your S3 bucket appears to be correct for allowing GET requests from any origin. However, the error message you're receiving suggests that the preflight request is failing, which is typically an OPTIONS request sent by the browser before the actual GET request to that.
To resolve this issue, you need to explicitly allow the OPTIONS method in your CORS configuration. Here's an updated CORS policy that should address the problem:
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET",
"HEAD"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]
https://docs.aws.amazon.com/AmazonS3/latest/userguide/ManageCorsUsing.html
Additionally, ensure that you're using the latest version of the AWS SDK for JavaScript in Node.js, as older versions might have issues with CORS handling.
If you're still experiencing issues after making these changes, double-check that the CORS configuration has been successfully applied to your S3 bucket and that there are no conflicting bucket policies or ACLs that might be interfering with access.
Remember that CORS is enforced by the browser, so testing with tools like curl or Postman won't reveal CORS issues. Always test in the actual browser environment where your application will run.
Lastly, if you're using Amazon CloudFront in front of your S3 bucket, ensure that it's configured to forward the necessary headers to S3 for CORS to work properly.
Sources
Use PutBucketCors with an AWS SDK or CLI - AWS SDK Code Examples
Use PutBucketCors with an AWS SDK or CLI - Amazon Simple Storage Service
answered 2 years ago
Updated answer CJ and removed options as you rightly stated.

The credentialing for the aws-sdk and the boto3 call are the same. "When you reference an S3 bucket in boto3, it can use the bucket's endpoint to discover its region. Unlike boto3, the AWS SDK for Node.js won't automatically deduce the region for S3 unless explicitly told, which means if you're connecting to a specific S3 bucket in a given region you need to be explicit about which region that bucket is in."