Simple HTTPS Setup S3 + CloudFlare

After a bit more investigation yesterday, I realized that github pages forces my website headers to always be 30x. This is not ideal. Furthermore, it makes it tough to use https protocol for my custom domain, which google now favors in search results.

Thought I was never one to fully blog like a hacker, I’m now even closer to that hacker-blogging destiny by hosting this page via S3 + CloudFront. Without going too deep into the “why”, I think with the limited time available for personal projects the low devops-y maintenance overhead for using static files instead of WordPress or fancy CMS is the main appeal.

The Steps

1. Register a domain.

For this, I used Google Domains, which I’ve gradually been moving all my domains to. Nothing against, GoDaddy and IWantMyName.com (my former domain management systems), but their UIs are clunky and always trying to sell me more domains. I wanted something simple an Google Domains delivers.

2. Make an S3 Bucket

You can read about the Amazon S3 bucket-making process elsewhere. The only caveat is to make sure that your bucket name matches your domain. For example mine is: omardelarosa.com. You will also need a second bucket to redirect the www. For me its www.omardelarosa. This is because of a small, quirk re: AWS S3 which is that CNAME redirects require the domain and bucket name to match. I’m guessing that’s for security purposes.

3. Use awscli to Sync Up

Anyway, once it’s made, I recommend using the awscli to sync up your files, which looks like this:

This will transfer all your files from the current directory to your bucket. In my case, I exclude a few files like node_modules/ and .git/, but use your own judgement. This is kinda up to you. Here’s what I’m using:

8. HTTPS

9. Adding a www redirect

Once those steps are complete, if you would like to add a www redirect. This can be done fairly simply by adding another S3 bucket called www.{yoursitebucket-name} and setting its redirect to your other bucket. Instructions for that can be found on the AWS Docs for redirects..

Conclusion

Once all these steps are done, you should have a fully functioning HTTPS static site hosted on S3 and backed (and cached) by CloudFlare.