Skip to content

Instantly share code, notes, and snippets.

@TeemuKoivisto
Last active May 27, 2017 19:54
Show Gist options
  • Save TeemuKoivisto/21a827d04541649e62a9a4034ffb74dc to your computer and use it in GitHub Desktop.
Save TeemuKoivisto/21a827d04541649e62a9a4034ffb74dc to your computer and use it in GitHub Desktop.
Guide to hosting static website to AWS S3

How to host a website on S3

S3 is a cheap way to host static files and pretty easy too (when you know how to do it)

What you need to have in order to do it:

  1. AWS account, you can get one through GitHub education > AWS education to get free credit
  2. Travis account (pretty straightforward, just log in with your GitHub account to create it)
  3. 10 minutes

Okey, you're all set. Let's go.

  1. Create a new S3 bucket and from the x > x view set its "Website Static Hosting" to yes with index.html as the main file
  2. Add this to your Bucket Policy > code
  3. Create a new IAM policy to allow Travis to push your code to S3. You can call it DumbPolicy and then paste this to the policy editor replaceing BUCKETNAME with your bucket's name > code
  4. Create a new IAM group and attach DumbPolicy to it
  5. Create a new IAM user to that group and copy and paste its Account Id and Account Secret to somewhere safe
  6. Next create a new repository in GitHub
  7. Clone the repository and create a file called index.html to the root of it with this code > code
  8. Create .travis.yml and you can paste this to bootstrap it (those email notifications are seriously annoying) > code
  9. Next you need to install travis gem using ruby >2.0 (you can check its specs from here(link)) using gem install travis
  10. Go to the root of the repository with terminal and enter travis setup s3 (here's the link to the travis' guide())
  11. Paste the Account ID and Secret that you copied previously
  12. git add -A and git commit your stuff and push it to GitHub (remember to have your repository switch set to build from Travis options!)
  13. After a short while Travis should build and copy your project to S3, incase something went wrong complain to me or consult the internet
  14. Go to AWS S3 console and follow the link to your S3 folder (eg. (example))
  15. You should see your amazing website! Truly a masterpiece
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment