Skip to content

How I elevated my AWS-hosted blog

Tags:

When I first started out with making a blog the first thing on my mind was to make use of the static webhosting-feature on AWS S3, meaning that we can basically put a index.html file under a root folder and tell S3 to display the content under a URL. The result is quite good once you get used to off-loading any new content in your S3 bucket whenever you want to post any new content.

Given my inexperience with web development I ended up with a horrible html and css hacking using templates and writing tons of code to produce minor content. You can read more about this experience here.

Web development tool

I went with WordPress as it is quite a classic by now and used by people of all skills. With all the templates that comes with WordPress you can get a very nice layout with little to none understanding of the customization. All you need to do is post your content and update a few titles or upload media. I ended up finding free templates on Google instead of using one of the boring ones half-free ones that comes by default with WordPress.

When it came to development itself and designing my website I setup a local WordPress on my laptop. First you need to pick a server for your web development that suits you. I went with WAMP but you might as well pick something like a linux-based LAMP. This is the guide I went with to setup WordPress locally using WAMP. One that is done you can download and install a WordPress-plugin called “Simply Static” that can generate your static content as a Zipfile that you want to extract and upload to S3.

Register your own domain

Once you have everything in your S3-bucket you can share it as public and call it a day. But there are several reasons why you want to take this further.

  1. Costs
    While hosting your website content on S3 is in itself quite cheap. With a cost of $0.023 per GB / Month while also supported by the Free tier-trial period of your first year, I would say this is close to free for your common private website. Thats why this is preferable to using a virtual server with a storage or other third-party solutions outside AWS.
  2. Latency
    By making use of CloudFront we can not only cache content to reduce the latency, but we also save money on frequent traffic to our S3 content using consolidated requests. Another great thing about CloudFront is that it will help us out with some security aspects such as traffic encryption.
  3. Better URL
    And last but not least we will leverage Route53 to register our own domain. This will give it more of a professional look and it will only cost us around 9-14$ / Year.
Image taken from StormIT Consulting

I found this video to be very helpful. You setup your domain (either through AWS or import one), customize CloudFront, requests a certificate in AWS, wait a few minutes, observe CNAME to show up as a record in your Route53 Hosted Zone and connect the CloudFront domain name with a A record in your Hosted Zone. Boom, its done!

There are a few tricky things regarding how you connect S3 and CloudFront, you can either make your S3 bucket public and connect it, but then anyone can access that content directly through the S3 URL so the point of CloudFront becomes less useful. Instead what you want to do is make the S3 bucket private and add a Bucket Policy that only allows access from CloudFront. I tried this but ended up with issues to access subpages running index.html. You can read more about how to restrict this access only to CloudFront and maybe you figure out how to work around the issue I experienced.

Improvements

The more I work with this blog I realise a few things I would like to add later on.

One thing for sure is the possibility of adding some kind of CI/CD pipeline to this blog. Adding any posts such as this one or making a small bug fix requires me to download a zip over all content and manually dump it in S3. While this only takes a few minutes to complete it’s still a very mundane process. I know that there are a few plugins for this but I prefer to make my own setup if its a small project that doesn’t do that much. Perhaps I can find a way to push commits to a GitHub repository which then could automatically pull any changes and deploy them to S3 using AWS CodePipeline.

Another is to find a better way of publishing new posts on my social feeds such as LinkedIn. I believe this can be done with something like AWS SNS or SQS. Will look into it later!

Join the conversation

Your email address will not be published. Required fields are marked *