Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to update AWS S3 CORS POLICY

I needed to change my AWS S3 bucket CORS policy to enable the upload of files for my ReactJS to AWS S3, but I keep getting this API response:

Expected params.CORSConfiguration.CORSRules to be an Array.

I am at a loss right now. Can anyone help?

Error message

like image 862
Lily Avatar asked Oct 29 '20 05:10

Lily


Video Answer


2 Answers

I'm not sure if this helps. I ran into this same problem recently and it seems like AWS made some changes with how we define our CORS configurations. For example, if you want to allow certain Methods on your S3 bucket in the past you have to do something like this on the editor:

<CORSConfiguration>
<CORSRule>
    <AllowedOrigin>*</AllowedOrigin>
    <AllowedMethod>GET</AllowedMethod>
    <AllowedMethod>PUT</AllowedMethod>
    <AllowedMethod>POST</AllowedMethod>
    <AllowedMethod>HEAD</AllowedMethod>
    <AllowedMethod>DELETE</AllowedMethod>
    <MaxAgeSeconds>3000</MaxAgeSeconds>
    <AllowedHeader>*</AllowedHeader>
</CORSRule>

The config below is equivalent to the one on the top but takes the form of an array.

[
    {
        "AllowedHeaders": [
            "*"
        ],
        "AllowedMethods": [
            "GET",
            "PUT",
            "POST",
            "HEAD",
            "DELETE"
        ],
        "AllowedOrigins": [
            "*"
        ],
        "ExposeHeaders": [],
        "MaxAgeSeconds": 3000
    }
]

Let me know if this helps. Thank you!

like image 160
FaitAccompli Avatar answered Sep 18 '22 12:09

FaitAccompli


We encountered the same error. We needed two fixes. (Not sure if this is helpful in your case):

  1. Pay attention to the type of quotes used: "" vs “”. Use the former
  2. Make sure you do not have a trailing comma on the second to last line, following the bracket.
like image 36
Peter Avatar answered Sep 16 '22 12:09

Peter