Google Cloud Storage Introduction
Google Cloud Storage is a “RESTful online file storage web service for storing and accessing data on Google Cloud Platform infrastructure” [Wikipedia], comparable to Amazon S3 or Azure Blob Storage. Let’s figure out how to use it!
Although I had used other products in the Google Cloud Platform (GCP) ecosystem, I hadn’t ever tried to host a static website from Cloud Storage. Its low cost and low barrier of entry make it an easy dip into GCP.
After an intial manual upload, I hooked up GitHub Actions automation to it to continuously deploy changes to a certain file. My go-to static website has become octocat, taken from https://api.github.com/octocat, so that’s what I used here.
Method and automation
Before beginning, you’ll need a Google Cloud Platform account and to install the
gcloud CLI. New customers get $300 of free credit to use on the paid features of GCP like GCS.
Log into the CLI and create a new project, linking it to your billing account (with or without the $300 credit 🤑). As always, it’s important to create an app-specific, rights-restricted service account. In this case, give it the Storage Admin role. Now you can use the
gsutil CLI (should also be installed with
gcloud) to create a bucket and upload your
index.html file to it. It’s that easy! 😍 Because this is a public website, open it up to the public internet and navigate to it at a website like https://storage.googleapis.com/your-bucket-name/index.html. Then hook it up to HTTP(S) Load Balancing and a custom domain as in this “Hosting a static website” tutorial.
And finally, try out a GitHub Actions workflow like this that uploads
index.html to GCS after every change!
About pricing: I take it from the GCP pricing calculator that hitting a 50 MB web page (!!!!) located in Iowa 50,000 times / month would cost under a dollar.