Skip to content

Instantly share code, notes, and snippets.

@catarak
Last active January 17, 2024 21:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save catarak/70c9301f0fd1ac2d6b58de03f61997e3 to your computer and use it in GitHub Desktop.
Save catarak/70c9301f0fd1ac2d6b58de03f61997e3 to your computer and use it in GitHub Desktop.
{
"Version": "2008-10-17",
"Id": "Policy1397632521960",
"Statement": [
{
"Sid": "Stmt1397633323327",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::YOUR_BUCKET_NAME_HERE/*"
}
]
}
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
  1. Create an S3 bucket. It can be called whatever you want. There are guides for this.
  2. Go to Properties -> Static Web Hosting and then "Enable website hosting". Then enter a value for the "Index Document". "index.html" is fine.
  3. Then, in Permissions -> Add CORS Configuration (Edit CORS Configuration if you've added a CORS configuration previously), paste in CORS.xml. This is for development only, as it allows CORS from any origin.
  4. Then, in Permissions -> Add Bucket Configuration (Edit Bucket Configuration if you've added a Bucket configuration previously), paste in Bucket.json. This makes all files public by default.
  5. Locate your AWS key and Secret Key. You can find this in the top AWS navigation under your name -> Security Credentials.
  6. Add the following lines to your .env file:
AWS_ACCESS_KEY=<your-aws-access-key>
AWS_SECRET_KEY=<your-aws-secret-key>
S3_BUCKET=<your-s3-bucket>
  1. Restart the app if it's running, and you should be good to go.
@lmccart
Copy link

lmccart commented Aug 1, 2016

hi @catarak, thanks for this! just setting this up for myself, I had a couple notes:

  • for step #2, it requires an index document field
  • for step #3, the first time the button actually says "add bucket policy"
  • for step #3 this field "Resource": "arn:aws:s3:::p5js-webeditor/*" needs to match your bucket name. maybe better to post the bucket.json with line "Resource": "arn:aws:s3:::YOUR-BUCKET-NAME/*"?

@catarak
Copy link
Author

catarak commented Nov 29, 2016

wow after MONTHS I finally corrected this gist 🎉

@adarzh-sys
Copy link

hey @catarak! i am assuming this needs an update, the permissions tab in aws has changed significantly since.

@catarak
Copy link
Author

catarak commented Oct 9, 2020

hey @catarak! i am assuming this needs an update, the permissions tab in aws has changed significantly since.

You're probably right! Feel free to suggest changes if you want to work on this.

@adarzh-sys
Copy link

adarzh-sys commented Oct 9, 2020

yes, here are the changes so far:

  • for step #2, there's also an error.html in the field for error document.
  • for step #4, it's now called bucket policy, adding the json is the same.

the rest is fine i guess, but i did turn off the "block public access", just in case.

@raclim
Copy link

raclim commented Jan 17, 2024

Wanted to add here that I think step #2 might not be required to set this up anymore, particularly for testing uploading images! It seems like its website endpoints are only equipped for GET or HEAD requests. I kept "enable web hosting" off and was able to get it running.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment