How to Host a Website on Amazon S3

Cat in Amazon Box

Audience: Novices who have no experience/knowledge of web development, who have never hosted a website themselves, but want to host a static website.

Amazon, isn’t that the site I buy shoes off of?

Most people know Amazon only as a big online department store, or even digital bookstore, but in 2002, they created a new department within their organization called Amazon Web Services (or AWS). This department provides a myriad of services to anyone needing processing, storing, sending, and hosting data. For example, one service, called Elastic Compute Cloud (EC2), lets you borrow a computer (that you connect and control through the internet) and use it for (mostly) anything you want. The “Cloud” in EC2 is the buzzword that you might have heard on the news. Amazon’s Web Services are all “in the cloud” because they present a simplified interface to interact with their enormously complex network of computers. Whereas in the past, increasing your computer’s speed by tenfold meant buying ten computers, hooking them up, and writing software to allow them all to share their resources, using Amazon, all you have to do is drag a slider. This saves lots of time and headache for people and so everyone seems to have gone bananas over the concept recently.

I thought we were talking about S3, not EC2.

Ah yes, so today we will use another service, Simple Storage Service (S3). This service lets you store files on an Amazon computer. These files can be then accessed by anyone connected to the Internet. This is handy because I just described a website.

How much does Amazon cost?

Amazon provides a calculator to figure this out. New users get a discount for a year, and Amazon charges you based on how much you use their service (which depends on how many files you store and how much traffic your site gets). I used the calculator, and assuming you store 1GB or less of stuff, and have 5000 visitors a month (which would be a likely scenario for a personal site), it’ll be free for the first year and 14 cents a month after that. Amazon can change their pricing at will, but in any case, the cost should be marginal.

Why use Amazon?

There are many companies have similar web services to Amazon. Microsoft has Microsoft Azure. Google has Google Cloud Platform . They all are competitors with similar services and pricing schemes. I simply chose Amazon because more people use them at the moment.

Note: There are also a plethora of smaller companies that let you “borrow” computers to use as a web server (which is what these Internet-connected file-serving computers are called). Some examples include GoDaddy, Dreamhost, and Hostgator. In contrast to Amazon, these companies are not “cloud computing” services, but are regular web hosting companies. What that means to you is that they charge fixed rates per-month (instead of dynamically varying the pricing depending on your usage of the service). This means that it is usually cheaper to use Amazon.

Lets do it.

Grab all the files you want to host and put them in a folder somewhere easy to get to, like the desktop. Create a new account on AWS. (You will need to provide a credit card) Go to your AWS batcave, ahem, management console. (And you were wondering why each service had an abbreviation...) Open the S3 tab in the management console, click “Create Bucket”. Name it “ryochiba-personalSite” or another title that describes your site. Note that the name of the bucket must be unique across all of the buckets hosted on Amazon, so prefix the bucket name with your name or something unique to make sure. Also, for the name:
  • Should not contain uppercase characters
  • Should not contain underscores (_)
  • Should be between 3 and 63 characters long
  • Should not end with a dash
  • Cannot contain two, adjacent periods
  • Cannot contain dashes next to periods (e.g., "my-.bucket.com" and "my.-bucket" are invalid)
The region specifies where the server will be located. If you live in ‘merica, US Standard should be fine. Click “Create”. Now, upload the files you want as part of your website. Right click on the bucket and click “properties” Now the properties for this bucket should show up at the bottom of the screen. Now we will allow anyone on the Internet to access our bucket. On the “Permissions” tab, click “Edit bucket policy”. In the text box, paste in the rule below, changing “example-bucket” to the name of your bucket. Then hit “Save”. { "Version":"2008-10-17", "Statement":[{ "Sid":"PublicReadForGetBucketObjects", "Effect":"Allow", "Principal": { "AWS": "*" }, "Action":["s3:GetObject"], "Resource":["arn:aws:s3:::example-bucket/*" ] } ] } Next, click on the “Website” tab and check “Enabled”. In the “Index Document” field, enter the name of the file that is your site’s index document. This file will be returned by the server when people access the “root” of your website. (if my site was www.ryochiba.com, it would be the file that gets returned when you type in ryochiba.com into the browser). Then, try going to the url in the Endpoint. Your file should be appear! Hey! I want my URL to be the domain name I bought! Now, log into the site that you bought your domain name from, and add a new CNAME entry in the DNS records whose value is the Endpoint url. It should take a couple of minutes to a few hours to have the changes be saved, so be patient. For reference, the official documentation.