Search code examples
google-cloud-platformgoogle-cloud-storagegoogle-cloud-cdn

How do you serve a static website using Google Cloud CDN, Google Cloud Storage, and a custom domain?


I'd like to set up a static website with files stored in a Google Storage bucket. I already own a custom domain and have, at a minimum, some barebone files to see if the site is setup successfully.

Ideally, I'd like to serve the content via SSL when accessing that custom domain and have the content cached from Google Storage utilizing Google Cloud CDN so that end users are served content from the CDN as opposed to being served from Cloud Storage directly.

I haven't been able to find the perfect setup for this yet or even solidify if Google enables/supports this scenario at this point (I've read that there may be a need to leverage a load balancer to support SSL, but nothing conclusive).

So far I have created a Google Storage bucket and uploaded the desired files. I then made the bucket publicly readable to ensure there aren't any permissions issues. From there I set up a load balancer to leverage my custom domain with the checkbox of Google Cloud CDN checked, the storage bucket just created, set as the backend, and the host file mapping set to the default settings.

UPDATE: It turned out just a few more steps were required. First, I needed to turn "Requestor Pays" off for the Storage bucket being utilized. Secondly, I needed to add permissions of "Storage Object Viewer" for "allUsers" (the legacy permission won't work here). Lastly, I had to both set the "A" and "AAAA" records to the IPV4 and IPV6 addresses of my Load Balancer for the DNS config on my domain name (and clear all previous values so that they were only referring to the new ones). After all of this was completed, everything is working as it should be :)

Thanks to both Cloud Ace (for leading me in the right direction) and a Google Customer Engineer that I met last week (for referring me to this article for reference: https://medium.com/@marco_37432/create-a-custom-domain-cdn-with-google-beta-7ad9531dfbae)!


Solution

  • When you create HTTP(S) Load Balancer, there should be a Certificate section in Frontend configuration if you set the protocol to HTTPS, also preserve a static IP. Then you can configure the DNS to point the domain to this IP.