Yandex Cloud
  • Services
  • Solutions
  • Why Yandex Cloud
  • Pricing
  • Documentation
  • Contact us
Get started
Language / Region
© 2022 Yandex.Cloud LLC
Yandex Cloud CDN
  • Getting started
  • Step-by-step instructions
    • All instructions
    • Resources
      • Creating a resource
      • Editing basic settings of a resource
      • Configuring resource caching
      • Configuring log export
      • Pre-loading files to CDN servers
      • Purging resource cache
      • Configuring request and response headers
      • Configuring CORS for responses to clients
      • Configuring HTTP methods
      • Enabling file compression
      • Enabling file segmentation
      • Enabling origin shielding
      • Disabling a resource
      • Deleting a resource
    • Origin groups
      • Creating an origin group
      • Editing an origin group
      • Connecting an origin group to a resource
      • Deleting an origin group
  • Practical guidelines
    • Publishing game updates
    • Integrating an L7 load balancer with the CDN and Object Storage
    • Blue-green and canary deployment
  • Concepts
    • Service overview
    • Resource
    • Origins and origin groups
    • Exchanging data between clients and the CDN
      • Overview
      • TLS certificates
      • CORS
      • Compressing content
    • Exchanging data between the CDN and origins
      • Overview
      • Host header
      • Segmenting content
      • Origin shielding
    • Caching content
    • Exporting logs
    • Quotas and limits
  • Access management
  • Troubleshooting
  • API reference
    • Authentication in the API
    • gRPC
      • Overview
      • CacheService
      • OriginGroupService
      • OriginService
      • ProviderService
      • RawLogsService
      • ResourceService
      • OperationService
    • REST
      • Overview
      • Cache
        • Overview
        • prefetch
        • purge
      • OriginGroup
        • Overview
        • create
        • delete
        • get
        • list
        • update
      • Origin
        • Overview
        • create
        • delete
        • get
        • list
        • update
      • Provider
        • Overview
        • activate
        • listActivated
      • RawLogs
        • Overview
        • activate
        • deactivate
        • get
        • update
      • Resource
        • Overview
        • create
        • delete
        • get
        • getProviderCName
        • list
        • update
  • Pricing policy
  1. Step-by-step instructions
  2. Resources
  3. Creating a resource

Creating a resource

Written by
Yandex Cloud
  • Examples

To create a resource:

Management console
CLI
Terraform
  1. In the management console, select the folder where you want to create a resource.

  2. Select Cloud CDN.

  3. If you don't have any CDN resources, click Activate provider. A connection is established automatically.

  4. Click Create resource.

  5. Under Content, select Content query From one origin or From origin group:

    • When requesting content From one origin, select an Origin type: Server, Bucket, or L7 load balancer. Specify an origin. For more information about types, see Origins and origin groups.

    • When requesting content from an Origin group, select an origin group or create a new one:

      • Click Create new.
      • Enter a Group name.
      • Configure Origins:
        • Specify the Origin type: Server, Bucket, or L7 load balancer. For more information about types, see Origins and origin groups.
        • Specify an origin.
        • Select the Priority: Active or Backup. For more information about priorities, see Origin groups.
      • 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.

  6. Under Domain names for content distribution, enter the 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 can't 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.

  7. In the Advanced section:

    1. Select Origin request protocol.
    2. Select a client redirect method: Don't use, HTTP to HTTPS, or HTTPS to HTTP.
    3. Enable or disable End-user access to content.
    4. If you selected the HTTP protocol, under Certificate type, select Don't use. Otherwise, select Let's Encrypt® or Your certificate. For more information, see Configuring TLS certificates for HTTPS connections between clients and the CDN.
    5. Select a Host header value: Primary domain name, Forward, or select Custom and input the Header value. For more information, see Host header in CDN server requests to origins.
  8. 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.

  1. If it's your first time creating a resource, start by connecting to the provider:

    yc cdn provider activate --type gcore
    
  2. View a description of the CLI create resource command:

    yc cdn resource create --help
    
  3. Get a list of origin groups in the folder:

    yc cdn origin-group list --format yaml
    

    Result:

    - id: "90209"
      folder_id: somefolder7p3l5eobbd
      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: b1g86q4m5vej8lkljme5
      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
    
  4. Create a resource:

    yc cdn resource create <resource domain name> \
      --origin-group-id <origin group ID> \
      --origin-protocol <protocol for origins>
    
    • Instead of the --origin-group-id, you can specify the origin domain name using the --origin-custom-source flag.
    • Possible --origin-protocol values are HTTP, HTTPS, and MATCH (same as the client's).

    For more information about the yc cdn resource create command, see the CLI reference.

Make sure the CDN provider is activated before you start using CDN resources. You can activate it in the management console or using the YC CLI command:

yc cdn provider activate --folder-id <folder ID> --type gcore

If you don't have Terraform, install it and configure the Yandex Cloud provider.

  1. In the configuration file, describe the parameters of the CDN resource to create:

    • cname: The primary domain name used for content distribution. Required parameter.
    • active: A flag that indicates if content is available to end users. True: Content from the CDN is available to clients. Optional parameter, defaults to True.
    • origin_protocol: Origin protocol. Optional parameter, defaults to http.
    • secondary_hostnames: Additional domain names. Optional.
    • origin_group_id: ID of the origin group. Required parameter. Use the ID from the description of the origin group in the yandex_cdn_origin_group resource.

    Example configuration file structure:

    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
    }
    

    For more information about yandex_cdn_resource parameters in Terraform, see the provider documentation.

  2. In the command line, go to the directory with the Terraform configuration file.

  3. Check the configuration using the command:

    terraform validate
    

    If the configuration is correct, the following message is returned:

    Success! The configuration is valid.
    
  4. Run the command:

    terraform plan
    

    The terminal will display a list of resources with parameters. No changes are made at this step. If there are errors in the configuration, Terraform points them out.

  5. Apply the configuration changes:

    terraform apply
    
  6. 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
    

It takes approximately 15 minutes to create a resource.

Examples

CLI

Create a resource with HTTP:

yc cdn resource create testexample.com \
  --origin-group-id 90209 \
  --origin-protocol HTTP

Result:

id: someidkfjqjfl325fw

...

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

Was the article helpful?

Language / Region
© 2022 Yandex.Cloud LLC