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:
This page walks you through the following procedures:
- Create a Cloud Storage bucket to store your content.
- Enable the required services.
- Create an
EdgeCacheOriginresource to connect Media CDN to your bucket. - Create an
EdgeCacheServiceresource to configure request routing and caching for content in the origin. - Test whether a response is being cached.
Before you begin
Make sure that you have the following:
Access to Media CDN for your current project.
The Google Cloud CLI installed. Use version 345.0.0 or later.
If required, use
gcloud versionto check the version andgcloud components updateto update your installed gcloud CLI.The gcloud CLI provides the
gcloud edge-cachesub-command group for managing both new and existing Media CDN configurations.The Identity and Access Management (IAM) permissions required to create Media CDN resources.
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
- Storage Admin role
(
roles/storage.admin)
To enable SSL on Media CDN
- Certificate Manager Editor role (
roles/certificatemanager.editor)
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.
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.
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
Enable the Network Services API.
Enable the Certificate Manager API.
gcloud
Enable the Network Services API:
gcloud services enable networkservices.googleapis.comEnable 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
In the Google Cloud console, go to the Media CDN page.
Click the Origins tab.
Click Create origin.
Enter the name for the origin as
cloud-storage-origin.Optional: Enter a description for the origin.
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.
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 originADDRESS: 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 formatprojects/PROJECT/locations/globalORIGIN_ID: the short name of the new originADDRESS: the bucket name,gs://my-bucketIf you have an external origin instead, replace
ADDRESSwith the FQDN or IP address.