10

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>
Skyler James Fagan
  • 101
  • 1
  • 1
  • 4

2 Answers2

26

Copy paste example

[
 {
    "AllowedHeaders": [
        "*"
    ],
    "AllowedMethods": [
        "GET",
        "HEAD"
    ],
    "AllowedOrigins": [
        "*"
    ],
    "ExposeHeaders": []
 }
]
TRomesh
  • 4,323
  • 8
  • 44
  • 74
Israel Perales
  • 2,192
  • 2
  • 25
  • 30
0

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": []
 }
]