Creating a resource
To create a resource:
-
In the management console
, select the folder to create a resource in. -
Select Cloud CDN.
-
If you do not have any CDN resources, click Activate provider. A connection is established automatically.
-
Click Create resource.
-
Under Content, select Content query
From one origin
orFrom origin group
:-
When requesting content
From one origin
, select an Origin type:Server
,Bucket
, orL7 load balancer
. Specify an origin. For more information about types, see Origins and origin groups. -
When requesting content from an
From origin group
, select an origin group or create a new one:- Click Create new.
- Enter Group name.
- Configure Origin:
- Specify the Origin type:
Server
,Bucket
, orL7 load balancer
. For more information about types, see Origins and origin groups. - Specify an origin.
- Select the Priority:
Active
orBackup
. For more information about priorities, see Origin groups.
- Specify the Origin type:
- Add other origins if needed.
- Click Create. In the Origin group field, you will see the name of the created group.
For more information, see Origins and origin groups.
-
-
Under Domain names for content distribution, enter Domain name. You can add multiple Domain names. Names containing characters other than ASCII (for example, Сyrillic) and Punycode
are supported. The first name is considered the primary domain name.Warning
After you create a resource, you cannot change the primary domain name.
In the settings of your DNS hosting, create CNAME records for the specified domain names using the value displayed at the bottom of the Domain names for content distribution section. For more information, see Domain names for content distribution.
-
Under Additional:
-
Select Origin request protocol.
-
Select a client redirect method:
Don't use
orHTTPS to HTTP
.To enable a client redirect from HTTP to HTTPS, create a CDN resource without a redirect and get a TLS certificate for your domain name. Next, in the CDN resource settings, select the
HTTP to HTTPS
client redirect method. -
Enable or disable Access to content.
-
In the Certificate type field, select one of the options:
Don't use
: Resource will only be available over HTTP.Let's Encrypt®
: Certificate will be issued by the CDN provider. You will not be able to manage such a certificate from Certificate Manager.Certificate from Certificate Manager
: Select a certificate in Certificate Manager. This can be both a Let's Encrypt® certificate and a user certificate.
For more information, see Configuring TLS certificates for HTTPS connections between clients and the CDN.
-
Select the Host header value (
Primary domain name
orForward
) or chooseCustom
and enter the Header value. For more information, see Host header in CDN server requests to origins.
-
-
Click Create.
If you don't have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
If you have not created resources before, connect to the provider first:
yc cdn provider activate --type gcore
-
View a description of the CLI create resource command:
yc cdn resource create --help
-
Get a list of origin groups in the folder:
yc cdn origin-group list --format yaml
Result:
- id: "90209" folder_id: somefolder7p******** name: test-group-1 use_next: true origins: - id: "561547" origin_group_id: "90209" source: www.example2.com enabled: true backup: true - id: "561546" origin_group_id: "90209" source: www.example1.com enabled: true - id: "90208" folder_id: b1g86q4m5ve******** name: test-group use_next: true origins: - id: "561545" origin_group_id: "90208" source: www.a2.com enabled: true backup: true - id: "561544" origin_group_id: "90208" source: www.a1.com enabled: true
-
Create a resource:
yc cdn resource create <resource domain name> \ --origin-group-id <origin group ID> \ --origin-protocol <protocol for origins>
- Instead of
--origin-group-id
, you can specify the origin domain name using the--origin-custom-source
flag. - Possible
--origin-protocol
values areHTTP
,HTTPS
, andMATCH
(same as the client's).
For more information about the
yc cdn resource create
command, see the CLI reference. - Instead of
Make sure the CDN provider is activated before you start using CDN resources. You can activate it in the management console
yc cdn provider activate --folder-id <folder ID> --type gcore
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
In the configuration file, describe the parameters of the CDN resource to create:
terraform { required_providers { yandex = { source = "yandex-cloud/yandex" version = "0.69.0" } } } provider "yandex" { token = "<OAuth>" cloud_id = "<cloud ID>" folder_id = "<folder ID>" zone = "<availability zone>" } resource "yandex_cdn_resource" "my_resource" { cname = "cdn1.yandex-example.ru" active = false origin_protocol = "https" secondary_hostnames = ["cdn-example-1.yandex.ru", "cdn-example-2.yandex.ru"] origin_group_id = yandex_cdn_origin_group.my_group.id }
Where:
cname
: Primary domain name used for content distribution. This is a required parameter.active
: Flag indicating whether content is available to end users.True
: Content from the CDN is available to clients. This is an optional parameter. The default value istrue
.origin_protocol
: Origin protocol. This is an optional parameter. The default value ishttp
.secondary_hostnames
: Additional domain names. This is an optional parameter.origin_group_id
: ID of the origin group. This is a required parameter. Use the ID from the description of the origin group in theyandex_cdn_origin_group
resource.
For more information about
yandex_cdn_resource
parameters in Terraform, see the provider documentation . -
In the command line, go to the directory with the Terraform configuration file.
-
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into the terminal and press Enter.You can check the changes to the CDN resource in the management console
or using the CLI:yc cdn resource list
Use the create REST API method for the Resource resource or the ResourceService/Create gRPC API call.
The new resource will start running properly after the CNAME record that you created on your DNS hosting (see the section about domain names used for content distribution) is propagated across DNS servers. This might take a few hours.
For a resource in Cloud CDN, you can specify additional settings provided by EdgeCenter, a CDN provider. For a complete description of its features, see the CDN provider's API documentation
Examples
Create a resource with HTTP:
yc cdn resource create testexample.com \
--origin-group-id 90209 \
--origin-protocol HTTP
Result:
id: someidkfjq********
...
cname: testexample.com
active: true
...
origin_group_id: "90209"
origin_group_name: test-group-1
origin_protocol: HTTP
ssl_certificate:
type: DONT_USE
status: READY