Ditching WordPress for Jekyll - Part 2 - Deployment

WordPress   Jekyll   AWS

In Part 1 of this series we talked about all the great reasons to move away from WordPress towards a static site like Jekyll. In this post we will go over the basics of building, hosting, and updating a Jekyll site in AWS.

Building the Jekyll site

I use VS Code on Windows as my primary code editor. It’s free, it’s extensible, and I love it. So, it makes sense that I configure my Jekyll blog and edit the content using VS Code as well. Installing Ruby on Windows is a non-trivial undertaking that I have no interest in figuring out. Luckily, Jekyll has long ago been containerized and is available in Docker container form. I use Bret Fisher’s Jekyll Docker images to create and serve the site.

I navigate to the Jekyll directory and spin up a Docker container using the following command.

docker run -t -i -p 4000:4000 -v ${PWD}:/site bretfisher/jekyll-serve

The above syntax is Windows PowerShell specific; a better bet would have been to install Docker within a WSL environment and run consistent Bash commands across the board. As I work on editing my Jekyll files, the Docker container regenerates that static site so I can see the changes in real time by looking at my localhost version of the site.

Hosting

One of the biggest advantages for moving away from WordPress to a static site like Jekyll is the simplified hosting needs. It’s not that hosting a personal blog with the LAMP stack is a particularly difficult undertaking, but it creates a layer of complexity that I would rather not have.

This site is hosted entirely in S3 using the Static Site hosting property of the buckets. Roughly speaking, the deployment process requires you to create two S3 buckets: one for hosting the Jekyll _site folder contents, and another one for handling www-redirects.

Once the two S3 buckets are created and the site uploaded, we need to create a Route 53 DNS hosted zone. We then need to go to the Domain Name Registrar (I use an external service), and update name servers for our domain name. Once those changes are reflected and propagated through the Registrars DNS infrastructure, we can go back to Route 53 and create our A records for the domain name and the www.domain.com.

Once done we go to the Amazon Certificate Manager and create an SSL/TLS cert for the domain and any secondary domains we wish to use. Once the ACM certificate is validated, we can go to CloudFront and create CDN distributions for our site which will allow us to use HTTPS and to have working www redirects.

This completes the deployment process.

Updating

Updating the live site is a two step process:

  • Update the files in the S3 bucket that hosts the site
  • Invalidate CloudFront cache so the updated site can be updated throughout the CDN

Both of these steps are accomplished with AWS CLI commands.

Update the S3 bucket command exampple:

aws s3 sync _site s3://<bucketname>/ --delete

Creating cache invalidation command example:

aws cloudfront create-invalidation   \
--distribution-id <yourdistribution> \
--paths "/*"

References: