mattbutterfield.com

home | blog | music | photos

Migrating My Personal Web Projects from AWS EC2 to GCP Cloud Run

2021-04-05

Hello and welcome to my freshly refactored and redeployed website! For many years, my personal website and side projects were hosted on AWS. All of my web apps, written in various languages, including their databases, ran directly on a single EC2 instance. My complete setup was:

This all worked well for some time. In fact, I hadn’t even restarted the EC2 server in over 4 years:

12:03:31 up 1560 days, 12:56,  1 user,  load average: 0.00, 0.00, 0.00

I really liked that I could just SSH into my server and everything was right there for me to play around with. I felt like I had a lot of control over everything.

On the other hand, there were some pretty glaring issues. I didn’t have a clear plan for upgrades, backups, deploying new things, or handling more traffic. I wanted something better but was unsure of the best approach.

Containers, Kubernetes, GCP, and Cloud Run.

A lot has happened since I finished my AWS setup. Containers have become almost the default way to deploy things, and for good reason. Likewise, Kubernetes has become almost the default way to deploy containers, and it works great too. But for running a personal website and some other small webapps, Kubernetes is overkill, too expensive and complicated.

When Cloud Run was released on GCP, it was advertised as "Container to production in seconds." I decided to try it a few weeks ago to deploy a web app. I bought a domain name, spun up a Cloud SQL database, and set up Cloud Run to run my app at the new domain. The whole thing was up and running in under an hour. I was impressed.

Since then I have migrated everything, including this website, to Cloud Run and GCP. This has taken care of a lot of the issues I had before, and simplified some things quite a bit. HTTPS and email are set up for me. The databases are scalable and backed up automatically. With Cloud Run, I can containerize and run any app, map it to a domain, and scale it if needed. My complete setup now is:

One major thing to consider here is the cost. Cloud Run has a free tier, but if you just spin up an entirely new GCP project for each application you want to launch, including new Cloud SQL instances, it's going to get expensive very quickly. To mitigate this, I have only one GCP project, with one Cloud SQL instance to run the databases for my website and whatever other experiments I want to launch. My AWS setup cost only around $10 a month. GCP will probably be more expensive than that but hopefully not by much.

So that's it for now. I don't know if I'll stick with this setup for years to come like I did with AWS, but it seems pretty nice so far. Stay tuned for updates!