Set up a Media CDN service

This quickstart shows you how to set up a Media CDN service in front of a Cloud Storage bucket. You can use this configuration for testing or as the basis for a production environment.


To follow step-by-step guidance for this task directly in the Google Cloud console, click Guide me:

Guide me


This page walks you through the following procedures:

  1. Create a Cloud Storage bucket to store your content.
  2. Enable the required services.
  3. Create an EdgeCacheOrigin resource to connect Media CDN to your bucket.
  4. Create an EdgeCacheService resource to configure request routing and caching for content in the origin.
  5. Test whether a response is being cached.

Before you begin

Make sure that you have the following:

Required roles

To get the permissions that you need to complete the tasks in this document, ask your administrator to grant the following roles:

  • roles/networkservices.edgeCacheAdmin: Access to create, update, delete, and manage all Edge Cache resources.
  • roles/networkservices.edgeCacheUser: Access to view and use Edge Cache resources.
  • roles/networkservices.edgeCacheViewer: Read-only access to Edge Cache resources.

To create storage bucket

To enable SSL on Media CDN

You might also be able to get the required permissions with custom roles or other predefined roles.

Create a Cloud Storage bucket

Media CDN content can originate from locations such as a Cloud Storage bucket, a third-party storage location, or a load balancer.

In this quickstart, we'll store content in a Cloud Storage bucket.

  1. Create a publicly accessible Cloud Storage bucket and name it my-bucket.

    If you prefer not to make your Cloud Storage bucket publicly accessible, you must give Media CDN permissions to access the bucket. For more information, see Using private Cloud Storage buckets.

  2. Upload a file into the bucket.

Enable the required services

To configure and deploy Media CDN services, you need to enable both the Network Services API and the Certificate Manager API for your project.

Console

  1. Enable the Network Services API.

    Enable the API

  2. Enable the Certificate Manager API.

    Enable the API

gcloud

  1. Enable the Network Services API:

    gcloud services enable networkservices.googleapis.com
    
  2. Enable the Certificate Manager API:

    gcloud services enable certificatemanager.googleapis.com
    

For more information about enabling and disabling services, see the Service Usage documentation.

Create an EdgeCacheOrigin resource

Create an origin that points to your Cloud Storage bucket.

Console

  1. In the Google Cloud console, go to the Media CDN page.

    Go to Media CDN

  2. Click the Origins tab.

  3. Click Create origin.

  4. Enter the name for the origin as cloud-storage-origin.

  5. Optional: Enter a description for the origin.

  6. For Origin address, choose Select a Google Cloud Storage bucket, browse to the Cloud Storage bucket named my-bucket, and then click Select.

    If you have an external origin instead, choose Specify an FQDN or IP address, and then enter the FQDN or IP address.

  7. Click Create origin.

After approximately 10 minutes, the newly created EdgeCacheOrigin resource appears in the list of origins in your project on the Origins page.

To update an origin address, click the origin, and then click Edit.

gcloud

Use the gcloud edge-cache origins create command:

gcloud edge-cache origins create ORIGIN \
    --origin-address="ADDRESS"

Replace the following:

  • ORIGIN: the name of the new origin
  • ADDRESS: the bucket name, gs://my-bucket

If you have an external origin instead, replace ADDRESS with the FQDN or IP address.

To view the newly created origin, use the gcloud edge-cache origins list command.

To update the origin address, use the gcloud edge-cache origins update command.

API

Use the edgeCacheOrigins.create method:

POST https://networkservices.googleapis.com/v1/PARENT/edgeCacheOrigins?edgeCacheOriginId=ORIGIN_ID
{
  "name": "ORIGIN_ID",
  "originAddress: "ADDRESS"
}

Replace the following:

  • PARENT: the parent resource in the format projects/PROJECT/locations/global
  • ORIGIN_ID: the short name of the new origin
  • ADDRESS: the bucket name, gs://my-bucket

    If you have an external origin instead, replace ADDRESS with the FQDN or IP address.

To view the newly created origin, use the