Modernizing This Site
This is a quick post on how I’m updating this site. Currently, it’s hosted on an old Supermicro CSE-745 server sucking up the “free” electricity in my parents' basement. They have a gigabit fiber connection, but the site is definitely not as fast to load as it could be if you aren’t nearby. I’m going to move the site to AWS using CloudFront and an S3 bucket. This should be a bit faster and far more reliable.
I’ve also made the repository for this blog public on GitHub so you can see the changes as commits.
Setting up CloudFront and S3
I created a private S3 bucket in the US East (N. Virginia) region and uploaded the static site generated by Pelican to the bucket. I can use the sync command to easily keep the S3 bucket up to date with the latest generated files.
Next, I created a new CloudFront distribution using my S3 bucket’s REST API
domain name as the origin. I set the index.html
file as the default. Since the
S3 bucket itself is still private, I had CloudFront create an Origin Access
Identity and automatically update the IAM permissions on the bucket. This whole
process was crazy easy - I love AWS!
At this point, you can go to d3daredapnpa6l.cloudfront.net and see the site distributed by CloudFront. Neat! Of course the fonts don’t work properly because CORS is disabled and Pelican has generated all the links relative to pudar.net.
Next, I want to be able to access the site from my domain name pudar.net. My registrar is currently Namecheap, although I’m eventually going to transfer the domain over to AWS.
I’ve enforced HTTPS in CloudFront, so before I can add a CNAME record, I need to create an SSL certificate for pudar.net and add the domain name to the Alternate Domain Names list in the CloudFront distribution. The SSL certificate is free to create in AWS using Certificate Manager.
Finally, in the Namecheap DNS console I replaced the A + DynamicDNS record pointing to my parents’ house with a CNAME record to d3daredapnpa6l.cloudfront.net. Now, pudar.net is officially hosted on AWS, and I can disable the Nginx service on the server at my parents’ house.
Considerations for Cloudfront
CloudFront is a cache, so if you need to update your site, you need to
invalidate the S3 objects that have been updated. For example, when I add a new
post to the site, the index.html
changes to reflect the new post. That means I
can either wait 24 hours before the update will start being reflected on the
CloudFront distribution, or I can manually invalidate the changed objects. You
can invalidate 1000 paths per month, and after that each path is half a cent to
invalidate. See Why is CloudFront serving outdated content from Amazon
S3?
for more information.
Infrastructure as Code
The next step here is to model the entire set of infrastructure components using CloudFormation so that the entire stack can be easily created from scratch. I’ll detail this process in another blog post.
Face Lift
Additionally, I’ve decided to move from Pelican to Jekyll mostly for the better themes available. I’ll outline this process in the next post.