[Yandex Cloud documentation](../../../index.md) > [Tutorials](../../index.md) > [Application solutions](../index.md) > Creating a website > [Static website in Object Storage with access via Cloud CDN](index.md) > Management console, CLI, and API

# Setting up static website hosting in a Yandex Object Storage bucket with Yandex Cloud CDN access


To [set up static website hosting](index.md) in a bucket with CDN access using the Yandex Cloud management console, CLI, or API:

1. [Get your cloud ready](#before-you-begin).
1. [Add a certificate to Certificate Manager](#add-certificate).
1. [Create a bucket in Object Storage and upload your website files to it](#create-bucket).
1. [Set up static website hosting](#hosting).
1. [Create a CDN resource](#create-cdn-resource).
1. [Configure DNS for the CDN resource](#configure-dns).
1. [Test the CDN](#check-cdn).

If you no longer need the resources you created, [delete them](#clear-out).


## Getting started {#before-you-begin}

Sign up for Yandex Cloud and create a [billing account](../../../billing/concepts/billing-account.md):
1. Navigate to the [management console](https://console.yandex.cloud) and log in to Yandex Cloud or create a new account.
1. On the **[Yandex Cloud Billing](https://center.yandex.cloud/billing/accounts)** page, make sure you have a billing account linked and it has the `ACTIVE` or `TRIAL_ACTIVE` [status](../../../billing/concepts/billing-account-statuses.md). If you do not have a billing account, [create one](../../../billing/quickstart/index.md) and [link](../../../billing/operations/pin-cloud.md) a cloud to it.

If you have an active billing account, you can create or select a [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) for your infrastructure on the [cloud page](https://console.yandex.cloud/cloud).

[Learn more about clouds and folders here](../../../resource-manager/concepts/resources-hierarchy.md).


### Required paid resources {#paid-resources}

The infrastructure support cost for a bucket-hosted site with CDN access includes:
* Fee for outgoing traffic from CDN servers (see [Cloud CDN pricing](../../../cdn/pricing.md)).
* Fee for storing data in Object Storage, data operations, and outgoing traffic (see [Object Storage pricing](../../../storage/pricing.md)).
* Fee for public DNS queries and [DNS zones](../../../dns/concepts/dns-zone.md) if using [Yandex Cloud DNS](../../../dns/index.md) (see [Cloud DNS pricing](../../../dns/pricing.md)).


## Add a certificate to Certificate Manager {#add-certificate}

Certificates from [Yandex Certificate Manager](../../../certificate-manager/index.md) are supported. You can [issue a new Let's Encrypt® certificate](../../../certificate-manager/operations/managed/cert-create.md) or [upload one of your own](../../../certificate-manager/operations/import/cert-create.md).

The certificate must be located in the same [folder](../../../resource-manager/concepts/resources-hierarchy.md#folder) as your CDN resource.

For a Let's Encrypt® certificate, pass an [ownership check](../../../certificate-manager/operations/managed/cert-validate.md) for the domain specified in the certificate.


## Create a bucket in Object Storage and upload your website files to it {#create-bucket}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select a folder.
  1. Navigate to **Object Storage**.
  1. At the top right, click **Create bucket**.
  1. In the ** Name** field, enter a name for the bucket, e.g., `example.com`.
  1. Click **Create bucket**.
  1. Create a website home page file named `index.html` on your computer.
     
      {% cut "Example of the `index.html` file" %}
      
      ```html
      <!DOCTYPE html>
      <html>
        <head>
          <title>My site</title>
        </head>
        <body>
          <p>The site is working</p>
        </body>
      </html>
      ```
      
      {% endcut %}
  1. On the bucket page, click ![image](../../../_assets/console-icons/arrow-up-from-line.svg) **Upload** and select `index.html`.

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. Create a bucket in the default folder:

      ```bash
      yc storage bucket create --name <bucket_name> \
        --public-read \
        --public-list
      ```

      Where:
      * `--name`: Bucket name, e.g., `example.com`. This is a required setting. For more information, see [Bucket naming rules](../../../storage/concepts/bucket.md#naming).
      * `--public-read`: Enables public read access to bucket objects.
      * `--public-list`: Enables public view access to the list of bucket objects.

      Result:

      ```text
      name: example.com
      folder_id: b1geoelk7fld********
      anonymous_access_flags:
        read: true
        list: true
      default_storage_class: STANDARD
      versioning: VERSIONING_DISABLED
      created_at: "2025-10-26T17:38:54.635027Z"
      resource_id: e3ef9cmb253k********
      ```

  1. Create a website home page file named `index.html` on your computer.
     
      {% cut "Example of the `index.html` file" %}
      
      ```html
      <!DOCTYPE html>
      <html>
        <head>
          <title>My site</title>
        </head>
        <body>
          <p>The site is working</p>
        </body>
      </html>
      ```
      
      {% endcut %}

  1. Upload the main page file to the bucket:

      ```bash
      yc storage s3api put-object \
        --body <local_file_path> \
        --bucket <bucket_name> \
        --key <object_path>
      ```

      Where:

      * `--body`: Path to the file you need to upload to the bucket, e.g., `index.html`.
      * `--bucket`: Bucket name, e.g., `example.com`.
      * `--key`: [Key](../../../storage/concepts/object.md#key) by which to store the object in the bucket, e.g., `index.html`.

      Result:
      ```text
      etag: '"b810d087812333c7dd9cfa80********"'
      request_id: 8e8714b8********
      ```

- API {#api}

  1. To create a bucket, use the [create](../../../storage/api-ref/Bucket/create.md) REST API method for the [Bucket](../../../storage/api-ref/Bucket/index.md) resource, the [BucketService/Create](../../../storage/api-ref/grpc/Bucket/create.md) gRPC API call, or the [create](../../../storage/s3/api-ref/bucket/create.md) S3 API method.

  1. Create a website home page file named `index.html` on your computer.
     
      {% cut "Example of the `index.html` file" %}
      
      ```html
      <!DOCTYPE html>
      <html>
        <head>
          <title>My site</title>
        </head>
        <body>
          <p>The site is working</p>
        </body>
      </html>
      ```
      
      {% endcut %}

  1. To upload the home page of the website, use the [upload](../../../storage/s3/api-ref/object/upload.md) S3 API method.

{% endlist %}


## Set up static website hosting {#hosting}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select a folder.
  1. Navigate to **Object Storage** and then to the bucket you want to set up hosting for.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/wrench.svg) **Settings**.
  1. Navigate to the **General** tab.
  1. In the **Read objects** and **Read object list** fields, select `For all`.
  1. Click **Save**.
  1. Select the **Website** tab.
  1. Under **Hosting**, in the **Home page** field, specify the absolute path to the file in the bucket for the website home page, e.g., `index.html`.
  1. Click **Save**.

  Use the link in **Link** to check the hosting.

- Yandex Cloud CLI {#cli}

  1. Set the hosting parameters for the bucket:

      ```bash
      yc storage bucket update --name <bucket_name> \
        --website-settings '{"index":"index.html"}'
      ```
      
      Where `--name` is the bucket name.

      Result:

      ```text
      name: example.com
      folder_id: b1geoelk7fld********
      default_storage_class: STANDARD
      versioning: VERSIONING_DISABLED
      acl: {}
      created_at: "2025-10-26T17:38:54.635027Z"
      website_settings:
        index: index.html
        redirect_all_requests: {}
      resource_id: e3ef9cmb253k********
      ```

- API {#api}

  To set up hosting for a static website, use the [update](../../../storage/api-ref/Bucket/update.md) REST API method for the [Bucket](../../../storage/api-ref/Bucket/index.md) resource, the [BucketService/Update](../../../storage/api-ref/grpc/Bucket/update.md) gRPC API call, or the [upload](../../../storage/s3/api-ref/hosting/upload.md) S3 API method.

{% endlist %}


## Create a CDN resource {#create-cdn-resource}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select a folder.
  1. Navigate to **Cloud CDN**.
  1. Click **Create resource**.
  1. Configure the basic CDN resource settings:
      * Under **Content**:
        * Enable **Enable access to content**.
        * In the **Content query** field, select `From one origin`.
        * In the **Origin type** field, select `Bucket`.
        * In the **Bucket** field, select the bucket you need from the list.
        * Enable **Use bucket site**.
        * In the **Origin request protocol** field, select `HTTP`.
        * In the **Domain name** field, enter the domain name, e.g., `cdn.yandexcloud.example`.

          {% note alert %}

          The `cdn.yandexcloud.example` domain name will become the primary one, and you will not be able to edit it after you create a CDN resource.

          {% endnote %}

      * Under **Additional settings**:
        * In the **Redirect clients** field, select `HTTP to HTTPS`.
        * In the **Certificate type** field, specify `Use from Certificate Manager` and select a [certificate](#add-certificate) for the `cdn.yandexcloud.example` domain name.
        * In the **Host header** field, select `Custom` and, in **Header value**, specify the origin domain name in `<name_of_bucket_with_files>.website.yandexcloud.net` format for the source bucket to respond to CDN server requests correctly.
  1. Click **Continue**.
  1. Keep the default settings for **Caching**, **HTTP headers and methods**, and **Additional settings** and click **Create and continue**.

- Yandex Cloud CLI {#cli}

  1. Create an origin group:

      ```bash
      yc cdn origin-group create \
        --name <origin_group_name> \
        --origin source=<name_of_bucket_with_files>.website.yandexcloud.net,enabled=true
      ```

      Where:
      * `--name`: Origin group name.
      * `--origin source`: Origin domain name in `<name_of_bucket_with_files>.website.yandexcloud.net` format, e.g., `example.com.website.yandexcloud.net`.

      Result:

      ```text
      folder_id: b1geoelk7fld********
      name: mys3-origin
      use_next: true
      origins:
        - id: "27904"
          origin_group_id: "42742158888********"
          source: example.com.website.yandexcloud.net
          enabled: true
          provider_type: ourcdn
      provider_type: ourcdn
     ```

  1. Create a CDN resource:

      ```bash
      yc cdn resource create \
        --cname <cdn_domain_name> \
        --origin-group-id <origin_group_ID> \
        --origin-protocol http \
        --cert-manager-ssl-cert-id <TLS_certificate_ID> \
        --host-header <name_of_bucket_with_files>.website.yandexcloud.net
      ```

      Where:
      * `--cname`: CDN resource domain name, e.g., `cdn.example.com`.
      * `--origin-group-id`: ID of the origin group for CDN created in the previous step.
      * `--origin-protocol`: Protocol the CDN resource will use to communicate with the origin, specify `http`.
      * `--cert-manager-ssl-cert-id`: TLS certificate ID that you saved earlier when creating the certificate.
      * `--host-header`: The Host header value. For the source bucket to respond to CDN server requests correctly, specify the origin domain name in `<name_of_bucket_with_files>.website.yandexcloud.net` format, e.g., `example.com.website.yandexcloud.net`.

      {% cut "Result" %}

      ```text
      id: bc8r4l7awapj********
      folder_id: b1geoelk7fld********
      cname: cdn.example.com
      created_at: "2025-10-26T17:45:08.171948Z"
      updated_at: "2025-10-26T17:45:08.171948Z"
      active: true
      options:
        edge_cache_settings:
          enabled: true
          default_value: "86400"
        browser_cache_settings: {}
        query_params_options:
          ignore_query_string:
            enabled: true
            value: true
        slice: {}
        host_options:
          host:
            enabled: true
            value: example.com.website.yandexcloud.net
        static_headers:
          enabled: true
        stale: {}
        allowed_http_methods:
          enabled: true
          value:
            - GET
            - HEAD
            - OPTIONS
        proxy_cache_methods_set:
          enabled: true
        disable_proxy_force_ranges:
          enabled: true
          value: true
        static_request_headers:
          enabled: true
        custom_server_name: {}
        ignore_cookie:
          enabled: true
          value: true
        secure_key:
          type: DISABLE_IP_SIGNING
      origin_group_id: "42742158888********"
      origin_group_name: mys3-origin
      origin_protocol: HTTP
      ssl_certificate:
        type: CM
        status: READY
        data:
          cm:
            id: fpq4nl8g1c4h********
      provider_type: ourcdn
      provider_cname: b5384481********.a.yccdn.cloud.yandex.net
      ```

      {% endcut %}

- API {#api}

  To create a CDN resource, use the [create](../../../cdn/api-ref/Resource/create.md) REST API method for the [Resource](../../../cdn/api-ref/Resource/index.md) resource or the [ResourceService/Create](../../../cdn/api-ref/grpc/Resource/create.md) gRPC API call.

{% endlist %}

{% note warning %}

After the CDN resource is set up, it may take up to 15 minutes for it to go live.

Make sure the new CDN resource is fully functional before proceeding with the next steps.

{% endnote %}


## Configure DNS for the CDN resource {#configure-dns}

The `cdn.yandexcloud.example` domain name must be mapped to the CDN using DNS records.

To set up DNS for a CDN resource:

1. Get the Cloud CDN provider domain name:

   {% list tabs group=instructions %}
   
   - Management console {#console}

     1. In the [management console](https://console.yandex.cloud), select a folder.
     1. Navigate to **Cloud CDN**.
     1. From the list of CDN resources, select the one with `cdn.yandexcloud.example` as its primary domain name.
     1. From **DNS settings** at the bottom of the page, copy the domain name in `e1b83ae3********.topology.gslb.yccdn.ru` format.

   {% endlist %}

1. On the website of your DNS hosting provider, navigate to the DNS settings.
1. Create or edit a CNAME record for `cdn.yandexcloud.example` so that it points to the domain name you copied:

   ```text
   cdn CNAME e1b83ae3********.topology.gslb.yccdn.ru
   ```

   {% note info %}
   
   Do not use an [ANAME](../../../dns/concepts/resource-record.md#aname) resource record with domain names for content distribution; otherwise, the end user will get a response from a CDN server not linked to the user geolocation. The response will always be the same for all users.
   
   {% endnote %}

   If you use Cloud DNS, follow this guide to configure the record:
   
   {% cut "Configuring DNS records for Cloud DNS" %}
   
   {% list tabs group=instructions %}
   
   - Management console {#console}
   
     1. In the [management console](https://console.yandex.cloud), select a folder.
     1. Navigate to **Cloud DNS**.
     1. If you do not have a public DNS zone, create one:

        1. Click **Create zone**.
        1. In the **Zone** field, enter the website domain name with a trailing dot: `yandexcloud.example.`.
        1. In the **Type** field, select `Public`.
        1. In the **Name** field, specify `example-dns-zone`.
        1. Click **Create**.
      
     1. Create a CNAME record for `cdn.yandexcloud.example` in the zone:

        1. Select `example-dns-zone`.
        1. Click **Create record**.
        1. In the **Name** field, specify `cdn`.
        1. In the **Type** field, specify `CNAME`.
        1. In the **Data** field, paste the copied value in `e1b83ae3********.topology.gslb.yccdn.ru.` format with a trailing dot.
        1. Click **Create**.

   {% endlist %}

   {% endcut %}


## Test the CDN {#check-cdn}

Wait for the DNS records to get updated (this may take several hours).

Check if the website is accessible: use the new URL, `cdn.example.com`, to open it. You should be redirected to the `https://cdn.example.com` website with a TLS certificate from Certificate Manager already connected and content sourced from Cloud CDN.


## How to delete the resources you created {#clear-out}

To shut down the infrastructure and stop paying for the resources you created:

1. [Delete](../../../dns/operations/zone-delete.md) the DNS zone named `example-dns-zone` if you created it in Cloud DNS.
1. Delete the CDN resource with `cdn.yandexcloud.example` as its primary domain name.
1. [Delete](../../../storage/operations/objects/delete.md) all objects from the bucket.
1. [Delete](../../../storage/operations/buckets/delete.md) the bucket.


#### Useful links {#see-also}

* [Setting up static website hosting in a Yandex Object Storage bucket with Yandex Cloud CDN access using Terraform](terraform.md)