Serving static files using Google Cloud CDN + Storage Bucket

Subhajit Dutta
BrewedByte
Published in
3 min readFeb 13, 2019

Google cloud CDN is — low latency, distributed content delivery solution. It has more than 100 POP (Point of presence) to make your assets highly available.

The Cloud CDN content delivery network works with HTTP(S) load balancing to deliver content to your users. The HTTP(S) load balancing configuration specifies the frontend IP addresses and ports on which Cloud CDN receives requests and the backends that originate responses to those requests.

We will see how the above definition works step and step, and also we will configure a cdn using GCloud Platform with SSL ( HTTPS) support.

Prerequisites

— — — — — — — —

Before proceeding further, lets see what are the initial steps to be taken to start configuring cdn according to this tutorial…

  1. You should have knowledge on configuring DNS records.
  2. You must already have an active domain and access to its control panel
  3. A GCloud Project

A. Create a Storage Bucket

— — — — — — — — — — — — — — — —

  1. Go to Google Cloud Platform ( https://console.cloud.google.com) and select your project.
  2. Search for “Storage” and click on “Storage” from the drop down or click on storage from left nav bar -> browse or check this link https://console.cloud.google.com/storage.
  3. Click on “CREATE BUCKET” button from top.
  4. Choose bucket name -> Select multi-regional -> your preferred bucket location.
  5. Click on “Create”

B. Creating Load Balancer

— — — — — — — — — — — — — — — —

  1. Search for Network Services -> Click on Load Balancing from left navigation drawer( See under Networking section ) or search from top search bar.
  2. Click on CREATE LOAD BALANCER -> Select HTTP(S) Load Balancing -> Start Configuring.
  3. Select Backend Configuration
  4. From right side select Backend Buckets -> Select your previously created bucket
  5. Select Frontend Configuration.
  6. From right side Name section -> Give name to your New Frontend IP and Port
  7. Select protocol HTTPS ( make sure you have an active domain or subdomain )
  8. From Certificate section, click on Create a New Certificate.
  9. Give a name to your new SSL certificate
  10. Select Create Google-managed certificate as create mode( Google mainly uses Lets Encrypt as CA )
  11. In domain section, give a subdomain*** name (eg. assets.example.com) that you will use for static assets serving. *** Assuming you currently does not have that sub-domain and you have access to domain provider to create one.
  12. Click on create
  13. Once created, again click on Load Balancing from left navigation
  14. Now you will see Load Balancers created by you. Click on Frontends tab
  15. Search for previously created config and note down the IP ADDRESS.
  16. *** Now go to your domain provider’s site and create a subdomain that should point to previously created frontend ip address. This subdomain can be served over https because google has already activated ssl for this.

C. Adding Load Balancer to CDN

  1. Go to Cloud CDN under Network Services from left nav
  2. Click on ADD ORIGIN
  3. Select your previously created Load Balancer
  4. Click on Add

Now you have successfully created a fully managed cloud cdn that is served over https.

To see if your domain ssl is successfully verified…

  1. Go to Load Balancing section from left bar -> Under Load Balancers tab and Name Column -> click on your previously created LB
  2. This will open Load balancer details section
  3. Under Frontend Section -> Click on your certificate under Certificate column.
  4. Check this image

To see what these statuses mean, check this link https://cloud.google.com/load-balancing/docs/ssl-certificates?hl=en_GB&_ga=2.131299983.-1697683271.1535389579&_gac=1.229135598.1549389793.Cj0KCQiAheXiBRD-ARIsAODSpWP6ccw-mH7igkjw7pYZdPpVsAbB9ceVWE7ed3bQfD-PT4KSVWfNwFsaAnY3EALw_wcB#domain-status

Final Steps:

Add some images or static files to your bucket and access them using your subdomain. Eg. https://assets.example.com/my_image.jpg

Note: Assets in bucket might not be available publicly. To make an asset public, go to permissions for that asset -> Add Entity User -> allUsers as Name.

--

--