Unable to update AWS S3 CORS POLICY

旧街凉风 提交于 2020-12-29 09:30:43

问题


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?


回答1:


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!




回答2:


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.



回答3:


To configure CORS for your static website the CORS object has to be in JSON format see aws docs cors configuration. To specify the actions allowed on that bucket you want to enable CORS on, you must define a set of CORS Rules. The CORS Rules is an array that holds a set of objects where each object corresponds to a particular rule. To learn more about how to define CORS Rules see aws cors rule. The error you are receiving is due the fact that your CORS Rule is in improper format. If you follow the above example by @FaitAccompli the error should be resolved.



来源:https://stackoverflow.com/questions/64585273/unable-to-update-aws-s3-cors-policy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!