How I created this Blog
I recently moved my websites from GoDaddy to AWS S3 for a lot of reasons and in the process decided I wanted to host a new blog on it as well. However, initially I wasn’t sure if it was possible since I wanted to use a CMS system for my blog to allow for simple posting and I figured something like WordPress or some sort of server-side functionality would be required. Upon some Googling and I came across this blog which covers the process so I won’t detail. Essentially, your AWS registered website, a couple of S3 buckets to store the website files, CloudFront to secure the website, Jekyll to act as the CMS, and AWS CLI Sync to upload new posts, are all that is necessary. However, there are a couple of additional points I would make.
First, the way Jekyll generates websites, or at least with the theme I used, Minimalist Mistakes, results in subfolders with html files within, rather than all of the html files at the root of the website like my other website, and thus why I hadn’t run into the problem before. When configured with CloudFront this created errors which were not generated when opening up the URL directly via the S3 URL or even when setting the DNS A records directly to S3 (http). Essentially, the behavior was that when opening up the website in a browser the homepage (index.html) would open just fine. The following error would occur, however, whenever clicking on a link as this would generate a /subfolder/index.html.
The resolution to the above error is to change the CloudFront Origin Domain Name and Path to include the region. AWS will provide a dropdown list which is very convenient but in this case it failed me. So the change is from proservicesstorage.com.s3.amazonaws.com to proservicesstorage.com.s3-website-us-east-.amazonaws.com. You can get the correct value by going to the S3 bucket properties > static website hosting and copying the URL from there.
The second thing to know is if you are not a Ruby developer you might jump right in and install ruby into the system or use the currently installed version. I ran into all kinds of permissions issues and was running everything as sudo which is just terrible and shameful. Alas, however, I discovered, RVM, which is a Ruby Version Manager, and that solved all of these problems. Sudo was put away and no longer needed. Nothing you will be doing in Jekyll needs root access. I used RVM on Ubuntu as well as my Mac which I published this on.
So now I have completed my goal of hosting my blog on AWS S3 using a CMS. The workflow is as follows.
- Create post on Atom with the Jekyll plug-in using MarkDown and save to local blog _posts directory. I can run
jekyll serve
while I am doing this to see the changes live. - Once, I am happy and I want to publish I run,
JEKYLL_ENV=production bundle exec jekyll build
, then I runaws s3 sync _site s3://proservicesstorage.com
, to upload the changes. Boom!
So how can this process be improved? From what I can tell, I could secure this more by removing public bucket access and restricting to CloudFront. I will automate the publishing process via the shell. The Atom plug-in is intriguing and may offer further integration and automation and is something I will investigate.
Leave a comment