Saturday 23 August 2014

Amazon Web Services (AWS): Configuring Amazon S3 to Host a Website

Open the Amazon Web Services (AWS) Management Console, and click S3 - Scalable Storage in the Cloud from the Storage & Content Delivery subheading.
"Amazon S3 provides highly durable and available cloud storage for a variety of content, ranging from web applications to media files. It allows you to offload your entire storage infrastructure onto the cloud, where you can take advantage of Amazon S3’s scalability and pay-as-you-go pricing to handle your growing object storage needs."

Now use Create Bucket, all websites and associated files are stored as objects within a logical container known as a "Bucket".  

When creating the initial Bucket consider the following;
  • A "bucket" name must be unique across Amazon S3.
  • If you are associating a FQDN with a "bucket" it should be configured with that FQDN
  • Once created, a "bucket" name cannot be changed
I have personally registered a new domain name for all my Amazon Web Services (AWS) studying, I managed to get awslab.co.uk. When you click Create Bucket enter the FQDN of your domain in the Bucket Name field and choose a Region, I have chosen Ireland as it is the closest to me! A Region in Amazon Web Services (AWS) is a geographical location in which AWS has a data center presence, inside Region's are Availability Zones.

Click on the Bucket you have just created, mine is awslab.co.uk and you will see a summary of the configuration.

Expand the Permissions configuration pane, and click Add Bucket Policy.



The Bucket Policy Editor for your defined Bucket will display a text area, Bucket Policies use JavaScript Object Notation.


This snippet of code which is borrowed from the Amazon Web Services (AWS) documentation store can be used and edited. You must change the "Resource": "arn:aws:s3:::yourFQDN/*" property to match the name of your Bucket.
{
  "Version":"2012-10-17",
  "Statement": [{
    "Sid": "Allow Public Access to All Objects",
    "Effect": "Allow",
    "Principal": "*",
    "Action": "s3:GetObject",
    "Resource": "arn:aws:s3:::awslab.co.uk/*"
  }
 ]
}


The next stage is to configure Logging for your Bucket, you should always separate out the primary website and the log files into different Buckets. Logging in Amazon Web Services (AWS) records visitor statistics such as source IP's etc.
Create a new Bucket and ensure you use a subdomain of the FQDN you are configuring logging for. Again I changed the Region to Ireland. Click Create, I will highlight how to configure Logging next.


Click on the primary Bucket that is going to host your website, expand the Logging pane of the summary. In the Target Bucket field, point to the subdomain logging.domain.co.uk you just created. The Target Prefix should be set to logs/.


Click on the primary Bucket and use the Actions menu, and select Upload.
The Upload - Select Files and Folders window will appear, I have download a free HTML web template for this example. Drag and drop the website files, and click Start Upload.

When the upload completes the files will be listed and the status of the transfer will have changed to Done.

Return to the S3 main screen, and select the primary Bucket again. Expand the Static Website Hosting pane, and select and highlight Enable Website Hosting and enter the file name of your website landing page, it should be index.html, default.html etc for the browser to dedicate it's the "Home Page". Click Save.

If you open a web browser and browse to the auto generated domain name your website will be view able. The auto generated domain name is made up of the region and bucket name. In my next post I will cover how to configure your Bucket and proper DNS domain name.