Tech · January 17, 2023

Static Content Publishing in S3

Just a summary of google works. This is my original work of the cicd-demo of mine solving my concern of hosting my website at minimal cost and effort without a ”server”.

Web site on S3

Actually, you don’t need things in AWS like Cloudfront or Route 53, S3 is capable to release content as a Web page: Look for Static website hosting under Properties in your S3 bucket.

Enable it and edit the stuff for your liking. You will have a web address to your S3 bucket for static hosting. Just a note that your S3 bucket will be readable to public as a result.

Too simple, right. Minimising the cost is very simple with your free tier in AWS. To me, I want to explore for a rather complete end-to-end publishing from CMS (e.g. WordPress), to deploy static content with CICD under AWS because I got too bored with Azure… 😀

CICD with CodePipeline from GitHub

One of the choice for versioning could be CodeCommit for solely AWS solution. You may save a bit step as me with CodeCommit and CodePipeline, as long as you can work with the IAM policies (simple anyway). Just a matter of personal choice, I use GitHub instead. Sithum has made a very good guide to do so. I’d rather not repeat here. Just add a note from his guide that instead of GitHub, you can select CodeCommit from the source for a complete AWS suit implementation.

Besides, I have made a simple step to remove .gitignore from the automatic publishing to S3 before the deployment.

First, you need to create a Build project under CodeBuild, say, RemoveGitIgnore

Insert the build command:

version: 0.2

phases:
  build:
    commands:
      - find . -name ".gitignore" -type f -delete
artifacts:
  files:
    - '**/*'

Add a stage in your pipeline after the Source before the Deploy, say, Remove Dummies.

Then you will be good on next run.

CloudFront and DNS

I won’t include much related to the DNS setup for custom domain. It’s rather depends on your need and preference of registrant. The action I took considering to avoid making the S3 bucket public, so I linked the S3 bucket with CloudFront for content distribution.

To start with, create a Distribution under CloudFront. You will have options to select your current S3 buckets. Find the one associated with your website. Note again, you don’t need to make your S3 bucket public.

Other items will be a matter of choice (or cost) like: alternative domains, cache scope, and SSL.

If you are curious like me, you may set and alternative domain to setup the CNAME in your DNS setting forwarding to the Cloudfront domain available after creation, and request a AWS managed certificate (free!) for your website.

This covers the basic.

With a further search on the WordPress integration with the flow mentioned about, I noted that there is a WordPress plugin to generate a static website. Thinking if it can be done by using LightSail injecting the git command to GitHub, but I stop here and rested for 4 months… 😀

Afterword

After setting the WordPress in LightSail, honestly I changed my mind. It’s rather easy and inexpensive to setup a WordPress site with LightSail, even with backup and CDN. What the demo-cicd would apply when you wish to have a rather static website with a protected content management server within your premises. Whether you need a GitHub for versioning and staging could be a sign issue.

Anyway, fun to play. 🙂