Serverless computing on AWS #5 Hosting your website (Part 1)

Hosting websites on AWS is dead easy and dead cheap. The page you are looking at now is hosted by AWS!

There are a couple of ways to host websites using AWS Simple Storage Services (S3):

  1. AWS S3 website hosting
  2. AWS S3 with AWS Cloudfront

I'll describe the steps required and the merits of both below.

Before you start: get yourself a domain name to host your website on. I suggest you get your domain from AWS Route53. It'll be easier to setup your site and you'll get a "free" certificate for secure, https bindings.

The page you are looking at now is hosted by AWS!

Use AWS S3 website hosting

Step 1

Create an S3 bucket for your website - give it the same name as your new domain:

Step 2

Go to the properties of your S3 bucket and enable website hosting:

Step 3

Create an index.html file and an error.html file and place them in the bucket. 

Step 4

Enable public access to your bucket so that objects in it can be accessed from the Internet. 

Add Bucket Policy to enable public access to all objects in bucket:

{
"Version": "2012-10-17",
"Id": "Policy1553588170247",
"Statement": [
{
"Sid": "Stmt1553588165210",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::blog.reedinside.com/*"
}
]
}

Step 5

Disable public access restrictions on bucket:

Step 6

Click on the Endpoint URL to verify that you are able to browse to it:

 Yuk, that's a pretty ugly URL, let's wire up your fancy new domain that we setup earlier. 

Step 7 

In Route 53, map your domain to your new S3 bucket. The target bucket can be selected from a drop down list in the Alias Target field.

Pros and Cons of this method

Pros 

  • Quick and easy to setup

Cons

  • Exposes your S3 bucket to the Internet 
  • Website hosted in one region, so slower when accessed from elsewhere
  • Setting the security of S3 buckets is multi-layered and complicated

Next I'll describe my preferred method of website hosting - using AWS S3 and Cloudfront