This is a collection of tips and tricks I learnt whilst setting up a static site hosted on Amazon S3 lately for one of my apps. Now, in all the instructions, make sure you replace ‘mywebsite.com’ wherever you see it with your applicable domain of course :)

Buy your domain

First buy your domain (not hosting). This should cost $10/year roughly. People recommend godaddy, but i went with unlimited-space because they didn’t charge extra for WHOIS privacy. However, they don’t supply DNS hosting, so you have to set that up separately.

DNS

Go to zerigodns.com and grab an account. Go into the DNS management and create a new domain: mywebsite.com.

In this domain, create two hosts, one with an empty subdomain, and one with a ‘www’ subdomain. The setup for these two entries should be as follows:

mywebsite.com
Type: A
174.129.25.170 

www.mywebsite.com
Type: CNAME
www.mywebsite.com.s3-website-us-east-1.amazonaws.com

The IP address against the ‘A’ entry is used so that anyone who forgets the ‘www’ gets send to wwwizer (a free service that requires no account), who will forward them to the ‘www.mywebsite.com’ which will properly forward them to S3.

Unless you bought your domain from someone who packages it with DNS hosting, you’ll need to connect your domain registrar with zerigo. You’ll have to go to your domain registrar (ie unlimited-space in my case) and set your nameservers to:

a.ns.zerigo.net
b.ns.zerigo.net
c.ns.zerigo.net
d.ns.zerigo.net
e.ns.zerigo.net

S3

In the AWS S3 console, make a new bucket called ‘www.mywebsite.com’. Right click > Properties on this bucket, and set up the following:

Bucket policy

In the ‘Permissions’ tab, edit the bucket policy to make it publicly readable. Set the bucket policy as per on this blog on ariejan.net, as follows:

{
  "Version":"2008-10-17",
  "Statement":[{
    "Sid":"AllowPublicRead",
        "Effect":"Allow",
      "Principal": {
            "AWS": "*"
         },
      "Action":["s3:GetObject"],
      "Resource":["arn:aws:s3:::www.mywebsite.com/*"
      ]
    }
  ]
}

Make sure you replace the ‘www.mywebsite.com’ above to match your s3 bucket name.

Website

In the website tab of the bucket properties, select ‘enabled’, put in index.html as your index document, and `error.html`` as your error document.

You will see the endpoint in this tab as well. It should look like www.mywebsite.com.s3-website-us-east-1.amazonaws.com. Just double check that it’s the same as the CNAME entry you made in your DNS settings.

That should be it! You’ve now got a static website for a fraction of the price of typical hosting. My rough calculations indicate that this should cost me ~$2 a year. Brilliant.

Thanks for reading! And if you want to get in touch, I'd love to hear from you: chris.hulbert at gmail.

Chris Hulbert

(Comp Sci, Hons - UTS)

iOS Developer (Freelancer / Contractor) in Australia.

I have worked at places such as Google, Cochlear, Assembly Payments, News Corp, Fox Sports, NineMSN, FetchTV, Coles, Woolworths, Trust Bank, and Westpac, among others. If you're looking for help developing an iOS app, drop me a line!

Get in touch:
[email protected]
github.com/chrishulbert
linkedin



 Subscribe via RSS