I need to configure CORS in s3 bucket the code I have isn't a valid JSON
Asked Answered
A

2

12

I am trying to make a photo gallery from my s3 photo bucket. the next step in my process is to configure CORS but when I use the code provided I get an error. Can someone please explain what I am doing wrong or how to change the code to valid JSON?

thanks for your help, its appreciated. Very new to this.

https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/s3-example-photos-view.html

Cross-origin resource sharing (CORS) The CORS configuration, written in JSON, defines a way for client web applications that are loaded in one domain to interact with resources in a different domain. Learn more 

 The CORS configuration must be written in valid JSON. API response Expected params.CORSConfiguration.CORSRules to be an Array

<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedOrigin>*</AllowedOrigin>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <AllowedHeader>*</AllowedHeader>
    </CORSRule>
</CORSConfiguration>
Aldwin answered 3/12, 2020 at 19:44 Comment(0)
Y
28

Copy paste example

[
 {
    "AllowedHeaders": [
        "*"
    ],
    "AllowedMethods": [
        "GET",
        "HEAD"
    ],
    "AllowedOrigins": [
        "*"
    ],
    "ExposeHeaders": []
 }
]
Yancy answered 13/1, 2021 at 5:55 Comment(0)
T
1

AWS has yet to update their document: https://docs.aws.amazon.com/AmazonS3/latest/userguide/ManageCorsUsing.html

However, their explanation on using JSON policy still stands.

[
 {
    "AllowedHeaders": [
        "*"
    ],
    "AllowedMethods": [
        "GET",
        "HEAD"
    // add more methods as required 
    // you may need PUT, POST, etc 
    ],
    "AllowedOrigins": [
        "*"
    // for better security explicitly write your exact source url.
    ],
    "ExposeHeaders": []
 }
]
Tributary answered 11/10, 2022 at 6:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.