I'm writing this answer cause I was stuck in the issue for almost a day.
Add CORS permission on AWS S3
- Open the specific bucket.
- Then click on the permission tab on the top

- Then scroll to the last, and you will find the CORS configuration. Just click on edit.

- Then paste the below configuration in
[
{
"AllowedHeaders": [
"*"
],
"AllowedMethods": [
"GET"
],
"AllowedOrigins": [
"*"
],
"ExposeHeaders": []
}
]
- You can also add your custom domains inside AllowedOrigin
Remove cache from API call
I have done the above change but still, I was facing the same issue again and again. I fixed that by disabling the cache of the API. I was using fetch to call the s3 URL. Below is the code for it.
fetch(
<s3 URL>,
{
method: 'GET',
headers: { "Cache-Control": 'no-cache' },
}
)
Originand other CORS request headers in the CloudFront Cache Behavior? - Michael - sqlbot