Home > database >  AWS S3: PUT requests only succeed if bucket CORS config contains AllowedOrigins: "*"
AWS S3: PUT requests only succeed if bucket CORS config contains AllowedOrigins: "*"

Time:01-30

I have a bucket in S3 to which I wish to PUT some data using JavaScript running on "http://cats.com".

To ensure only requests from "cats.com" can make PUT requests, I set the following as the CORS config in S3:

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "PUT",
            "POST",
            "DELETE"
        ],
        "AllowedOrigins": [
            "http://cats.com/"
        ],
        "ExposeHeaders": []
    }
]

Requests did not succeed. But if I set:

"AllowedOrigins": [
    "*"
],

PUT requests worked.

Could there be some kind of proxy or other networking service that is somehow changing the origin of the requests? Any pointers others can offer would be greatly appreciated.

CodePudding user response:

While typing this question I thought I'd check and see if removing the trailing slash changed the origin of the request as understood by Amazon.

Indeed it did. The following is the correct config for my requests:

"AllowedOrigins": [
    "http://cats.com"
],
  •  Tags:  
  • Related