In this lab, you configure Cloud Content Delivery Network (Cloud CDN) for a backend bucket and verify caching of an image. Cloud CDN uses Google's globally distributed edge points of presence to cache HTTP(S) load-balanced content close to your users. Caching content at the edges of Google's network provides faster delivery of content to your users while reducing serving costs.
In this lab, you learn how to perform the following tasks:
Create and populate a Cloud Storage bucket
Create an HTTP load balancer with Cloud CDN
Verify the caching of your bucket's content
For each lab, you get a new Google Cloud project and set of resources for a fixed time at no cost.
Sign in to Qwiklabs using an incognito window.
Note the lab's access time (for example, 1:15:00), and make sure you can finish within that time.
There is no pause feature. You can restart if needed, but you have to start at the beginning.
When ready, click Start lab.
Note your lab credentials (Username and Password). You will use them to sign in to the Google Cloud Console.
Click Open Google Console.
Click Use another account and copy/paste credentials for this lab into the prompts.
If you use other credentials, you'll receive errors or incur charges.
Accept the terms and skip the recovery resource page.
Task 1. Create and populate a Cloud Storage bucket
Cloud CDN content can originate from two types of backends:
Google Compute Engine virtual machine (VM) instance groups
Google Cloud Storage buckets
In this lab, you configure a Cloud Storage bucket as the backend.
Create a unique Cloud Storage bucket
In the Cloud Console, on the Navigation menu (), click Cloud Storage > Buckets.
Click Create.
For the name, enter a globally unique value, and click Continue.
For the Location Type, select Region.
For the Region dropdown, select .
Click Continue and leave the default selection in Choose a storage class for your data as-is.
Click Choose how to control access to objects.
Uncheck Enforce public access prevention on this bucket, select Fine-grained and then click Create.
Note: Even if the Enforce public access prevention on this bucket checkbox is cleared, the project's organization policy can still deny public access to the bucket contents.
Note the name of your storage bucket for the next subtask. It will be referred to as [your-storage-bucket].
Copy an image file into your bucket
Copy an image from a public Cloud Storage bucket to your own bucket.
In the Cloud Console, click Activate Cloud Shell ().
If prompted, click Continue.
Run the following command in Cloud Shell, replacing [your-storage-bucket] with your bucket's name:
In the Cloud Console, click Refresh to verify that "Public to internet Copy URL" now appears under the column called Public access.
Click on Copy URL under Public access to verify that you can access the image.
Exit Cloud Shell:
exit
Click Check my progress to verify the objective.
Create and populate a Cloud Storage bucket
Task 2. Create the HTTP load balancer with Cloud CDN
HTTP(S) load balancing provides global load balancing for HTTP(S) requests of static content to a Cloud Storage bucket (backend). When you enable Cloud CDN on your backend, your content is cached at a location at the edge of Google's network, which is usually far closer to the user than your backend is.
Start the HTTP load balancer Configuration
In the Cloud Console, go to the search bar at the top of the page, enter Network Services, and select the option that says Network Services Network management tools.
Select Load balancing and click + Create load balancer.
Under Type of load balancer, select Application Load Balancer (HTTP/HTTPS) and click Next.
Leave all the settings as default and click Configure.
For Load Balancer Name, type cdn-lb.
Configure the frontend
The host and path rules determine how your traffic will be directed. For example, you could direct video traffic to one backend and image traffic to another backend. However, you are not configuring the Host and path rules in this lab.
Click Frontend configuration.
Specify the following, leaving all other values with their defaults:
Property
Value (type value or select option as specified)
Protocol
HTTP
IP version
IPv4
IP address
Ephemeral
Port
80
Click Done.
Configure the backend
Click Backend configuration.
Click the dropdown that says Backend services & backend buckets and click Create a backend bucket.
For Name, type cdn-bucket.
Click Browse under Cloud Storage bucket.
Select your bucket, and click Select.
Check the box for Enable Cloud CDN.
Leave the remaining settings as-is.
Click Create.
Select your created Backend bucket and click OK.
Yes, enabling Cloud CDN is as simple as selecting Enable Cloud CDN!
Review and create the HTTP load balancer
Click Review and finalize.
Review the Backend Buckets and Frontend.
Click Create.
Wait for the load balancer to be created.
Click on the name of the load balancer (cdn-lb).
Note the IP address of the load balancer for the next task. It will be referred to as [LB_IP_ADDRESS].
Click Check my progress to verify the objective.
Create the HTTP Load Balancer with Cloud CDN
Task 3. Verify the caching of your bucket's content
Now that you have created the HTTP load balancer for your bucket and enabled Cloud CDN, it is time to verify that the image is cached on the edge of Google's network.
Time the HTTP request for the image
One way to verify that the image is cached is to time the HTTP request for the image. The first request should take significantly longer, because content is only cached at an edge location after being accessed through that location.
In the Cloud Console, click Activate Cloud Shell ().
If prompted, click Continue.
Store the IP address of the load balancer in an environment variable:
export LB_IP_ADDRESS=<Enter the IP address of the load balancer>
Run the following command 3 times for consecutive HTTP requests:
for i in {1..3};do curl -s -w "%{time_total}\n" -o /dev/null http://$LB_IP_ADDRESS/cdn.png; done
The output should look like this (do not copy; this is example output):
1.234357
0.009600
0.006652
In this example output, the second and third requests take less than 1% of the time of the first request. This demonstrates that the image was cached during the first request and accessed from an edge location on further requests. Depending on how far you placed your storage bucket and where your closest edge location is, you will see different results.
Explore the Cloud CDN logs
Another way to verify that the image got cached in the previous step, is to explore the Cloud CDN logs. These logs will contain information on when content was cached and when the cache was accessed.
While Cloud CDN logging is in Alpha, the following steps might not work as expected.
It might take a couple of minutes or page refreshes for the selections in steps 2-4 to appear.
In the Cloud Console, go to the search bar at the top of the page, enter Logging and select the option that says Logging Real-time logging management and analysis.
Under the Resource Type filter, select Application Load Balancer.
Next, scroll below the Application Load Balancer selection, find the Forwarding Rule Name area and select cdn-lb-forwarding-rule.
Next, scroll below the cdn-lb-forwarding-rule selection, find the URL Map Name area and select cdn-lab.
It might take a couple of minutes to select the Cloud CDN logs.
Expand the first log entry (on top).
Within the entry, expand the httpRequest and notice that the cacheLookup is true but there is no cacheHit field.
This illustrates that the cache did not contain the image on this first request.
Expand the jsonPayload and notice that the statusDetails field contains response_sent_by_backend.
This also illustrates that the image came from the backend bucket on this first request.
Close the current log entry and expand a different log entry.
Within the entry, expand the httpRequest and notice that the cacheHit is true.
This illustrates that the cache contained the image on this request.
Expand the jsonPayload and notice that the statusDetails field contains response_from_cache.
This also illustrates that the cache, instead of the backend, provided the image on this request.
The Cloud CDN logs clearly demonstrate that the image was provided from the backend on the first request. This request filled the cache on the edge location, and all future requests received the image from that cache.
Task 4. Review
In this lab, you configured Cloud CDN for a backend bucket by configuring an HTTP load balancer and enabling Cloud CDN with a simple checkbox. You verified the caching of the bucket's content by accessing an image multiple times and exploring the Cloud CDN logs. The first time you accessed the image, it took longer because the cache of the edge location did not contain the image yet. All other requests were quicker because the image was provided from the cache of the edge location closest to your Cloud Shell instance.
When you have completed your lab, click End Lab. Google Cloud Skills Boost removes the resources you’ve used and cleans the account for you.
You will be given an opportunity to rate the lab experience. Select the applicable number of stars, type a comment, and then click Submit.
The number of stars indicates the following:
1 star = Very dissatisfied
2 stars = Dissatisfied
3 stars = Neutral
4 stars = Satisfied
5 stars = Very satisfied
You can close the dialog box if you don't want to provide feedback.
For feedback, suggestions, or corrections, please use the Support tab.
Manual Last Updated: May 14, 2024
Lab Last Tested: May 14, 2024
Copyright 2022 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
Labs erstellen ein Google Cloud-Projekt und Ressourcen für einen bestimmten Zeitraum
Labs haben ein Zeitlimit und keine Pausenfunktion. Wenn Sie das Lab beenden, müssen Sie von vorne beginnen.
Klicken Sie links oben auf dem Bildschirm auf Lab starten, um zu beginnen
Privates Surfen verwenden
Kopieren Sie den bereitgestellten Nutzernamen und das Passwort für das Lab
Klicken Sie im privaten Modus auf Konsole öffnen
In der Konsole anmelden
Melden Sie sich mit Ihren Lab-Anmeldedaten an. Wenn Sie andere Anmeldedaten verwenden, kann dies zu Fehlern führen oder es fallen Kosten an.
Akzeptieren Sie die Nutzungsbedingungen und überspringen Sie die Seite zur Wiederherstellung der Ressourcen
Klicken Sie erst auf Lab beenden, wenn Sie das Lab abgeschlossen haben oder es neu starten möchten. Andernfalls werden Ihre bisherige Arbeit und das Projekt gelöscht.
Diese Inhalte sind derzeit nicht verfügbar
Bei Verfügbarkeit des Labs benachrichtigen wir Sie per E-Mail
Sehr gut!
Bei Verfügbarkeit kontaktieren wir Sie per E-Mail
Es ist immer nur ein Lab möglich
Bestätigen Sie, dass Sie alle vorhandenen Labs beenden und dieses Lab starten möchten
Privates Surfen für das Lab verwenden
Nutzen Sie den privaten oder Inkognitomodus, um dieses Lab durchzuführen. So wird verhindert, dass es zu Konflikten zwischen Ihrem persönlichen Konto und dem Teilnehmerkonto kommt und zusätzliche Gebühren für Ihr persönliches Konto erhoben werden.
In this lab, you configure Cloud CDN for a backend bucket and verify caching of an image.