Setting up static website hosting in a Yandex Object Storage bucket with Yandex Cloud CDN access
To set up static website hosting in a bucket with CDN access using the Yandex Cloud management console, CLI, or API:
- Get your cloud ready.
- Add a certificate to Certificate Manager.
- Create a bucket in Object Storage and upload your website files to it.
- Set up static website hosting.
- Create a CDN resource.
- Configure DNS for the CDN resource.
- Test the CDN.
If you no longer need the resources you created, delete them.
Getting started
Sign up for Yandex Cloud and create a billing account:
- Navigate to the management console
and log in to Yandex Cloud or create a new account. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVEorTRIAL_ACTIVEstatus. If you do not have a billing account, create one and link a cloud to it.
If you have an active billing account, you can navigate to the cloud page
Learn more about clouds and folders here.
Required paid resources
The infrastructure support cost for a bucket-hosted site with CDN access includes:
- A fee for outgoing traffic from CDN servers (see Cloud CDN pricing).
- Fee for data storage in Object Storage, data operations, and outbound traffic (see Object Storage pricing).
- Fee for public DNS requests and DNS zones if using Yandex Cloud DNS (see Cloud DNS pricing).
Add a certificate to Certificate Manager
Certificates from Yandex Certificate Manager are supported. You can issue a new Let's Encrypt® certificate or upload one of your own.
The certificate must be located in the same folder as your CDN resource.
For a Let's Encrypt® certificate, pass an ownership check for the domain specified in the certificate.
Create a bucket in Object Storage and upload your website files to it
- In the management console
, select Object Storage. - At the top right, click Create bucket.
- In the ** Name** field, enter a name for the bucket, e.g.,
example.com. - Click Create bucket.
-
Create a website home page file named
index.htmlon your computer.Example of the
index.htmlfile<!DOCTYPE html> <html> <head> <title>My site</title> </head> <body> <p>The site is working</p> </body> </html> - On the bucket page, click
Upload and selectindex.html.
If you do not have the Yandex Cloud CLI installed yet, install and initialize it.
By default, the CLI uses the folder specified when creating the profile. To change the default folder, use the yc config set folder-id <folder_ID> command. You can also set a different folder for any specific command using the --folder-name or --folder-id parameter.
-
Create a bucket in the default folder:
yc storage bucket create --name <bucket_name> \ --public-read \ --public-listWhere:
--name: Bucket name, e.g.,example.com. This is a required parameter. For more information, see Bucket naming rules.--public-read: Enables public read access to bucket objects.--public-list: Enables public view access to the list of bucket objects.
Result:
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******** -
Create a website home page file named
index.htmlon your computer.Example of the
index.htmlfile<!DOCTYPE html> <html> <head> <title>My site</title> </head> <body> <p>The site is working</p> </body> </html> -
Upload the main page file to the bucket:
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 by which to store the object in the bucket, e.g.,index.html.
Result:
etag: '"b810d087812333c7dd9cfa80********"' request_id: 8e8714b8********
-
To create a bucket, use the create REST API method for the Bucket resource, the BucketService/Create gRPC API call, or the create S3 API method.
-
Create a website home page file named
index.htmlon your computer.Example of the
index.htmlfile<!DOCTYPE html> <html> <head> <title>My site</title> </head> <body> <p>The site is working</p> </body> </html> -
To upload the home page of the website, use the upload S3 API method.
Set up static website hosting
- In the management console
, select Object Storage from the list of services and go to the bucket you want to configure hosting for. - In the left-hand panel, select
Settings. - Navigate to the General tab.
- In the Read objects and Read object list fields, select
For all. - Click Save.
- Select the Website tab.
- 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. - Click Save.
Use the link in Link to check the hosting.
-
Set the hosting parameters for the bucket:
yc storage bucket update --name <bucket_name> \ --website-settings '{"index":"index.html"}'Where
--nameis the bucket name.Result:
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********
To set up hosting for a static website, use the update REST API method for the Bucket resource, the BucketService/Update gRPC API call, or the upload S3 API method.
Create a CDN resource
- In the management console
, select Cloud CDN. - Click Create resource.
- 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.Alert
The
cdn.yandexcloud.exampledomain name will become the primary one, and you will not be able to edit it after you create a CDN resource.
-
-
Under Additional settings:
- In the Redirect clients field, select
HTTP to HTTPS. - In the Certificate type field, specify
Use from Certificate Managerand select a certificate for thecdn.yandexcloud.exampledomain name. - In the Host header field, select
Customand, in Header value, specify the origin domain name in<name_of_bucket_with_files>.website.yandexcloud.netformat for the source bucket to respond to CDN server requests correctly.
- In the Redirect clients field, select
-
- Click Continue.
- Keep the default settings for Caching, HTTP headers and methods, and Additional settings and click Create and continue.
-
Create an origin group:
yc cdn origin-group create \ --name <origin_group_name> \ --origin source=<name_of_bucket_with_files>.website.yandexcloud.net,enabled=trueWhere:
--name: Origin group name.--origin source: Origin domain name in<name_of_bucket_with_files>.website.yandexcloud.netformat, e.g.,example.com.website.yandexcloud.net.
Result:
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 -
Create a CDN resource:
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.netWhere:
--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, specifyhttp.--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.netformat, e.g.,example.com.website.yandexcloud.net.
Result
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
To create a CDN resource, use the create REST API method for the Resource resource or the ResourceService/Create gRPC API call.
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.
Configure DNS for the CDN resource
The cdn.yandexcloud.example domain name must be mapped to the CDN using DNS records.
To set up DNS for a CDN resource:
-
Get the Cloud CDN provider domain name:
Management console- In the management console
, select Cloud CDN. - From the list of CDN resources, select the one with
cdn.yandexcloud.exampleas its primary domain name. - From DNS settings at the bottom of the page, copy the domain name in
328938ed********.a.yccdn.cloud.yandex.netorcl-msa87*****.edgecdn.ruformat depending on your CDN provider.
- In the management console
-
On the website of your DNS hosting provider, navigate to the DNS settings.
-
Create or edit a CNAME record for
cdn.yandexcloud.exampleso that it points to the domain name you copied:cdn CNAME 328938ed********.a.yccdn.cloud.yandex.netNote
Do not use an 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.
If you use Cloud DNS, follow this guide to configure the record:
Configuring DNS records for Cloud DNS
Management console-
In the management console
, select Cloud DNS. -
If you do not have a public DNS zone, create one:
- Click Create zone.
- In the Zone field, enter the website domain name with a trailing dot:
yandexcloud.example.. - In the Type field, select
Public. - In the Name field, specify
example-dns-zone. - Click Create.
-
Create a CNAME record for
cdn.yandexcloud.examplein the zone:- Select
example-dns-zone. - Click Create record.
- In the Name field, specify
cdn. - In the Type field, specify
CNAME. - In the Data field, paste the copied value in
328938ed********.a.yccdn.cloud.yandex.net.orcl-msa87*****.edgecdn.ru.format (depending on your CDN provider) with a trailing dot. - Click Create.
- Select
-
Test the 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
To shut down the infrastructure and stop paying for the resources you created:
- Delete the DNS zone named
example-dns-zoneif you created it in Cloud DNS. - Delete the CDN resource with
cdn.yandexcloud.exampleas its primary domain name. - Delete all objects from the bucket.
- Delete the bucket.