Connecting a bucket as a disk in Windows
In this tutorial, you will use rclone
Note
This section describes how to connect a bucket in Windows. When connecting in other OSs, see the official rclone documentation
To mount your bucket as a disk:
- Prepare your cloud.
- Set up a work environment.
- Create a service account.
- Create a static access key.
- Create a bucket.
- Set up a connection to Object Storage.
- Mount the bucket.
- Set up the mounting service.
If you no longer need the resources you created, delete them.
Getting started
Sign up for Yandex Cloud and create a billing account:
- Go to the management console
and log in to Yandex Cloud or create an account if you do not have one yet. - On the Yandex Cloud Billing
page, make sure you have a billing account linked and it has theACTIVE
orTRIAL_ACTIVE
status. If you do not have a billing account, create one.
If you have an active billing account, you can go to the cloud page
Learn more about clouds and folders.
Required paid resources
The cost for bucket support includes:
- Fee for storing data in a bucket (see Object Storage pricing).
- Fee for data operations (see Object Storage pricing).
Set up a working environment
-
Download and install the winfsp distribution
from the developer website. -
Download the archive with sysinternals suite utilities
from the developer's website and unpack it to your local working folder. -
Download the Windows Service Wrapper (WinSW) executable file
depending on your OS configuration and save it to a separate folder. -
Download the archive with the rclone utility
from the developer's website and unpack it to your local working folder. -
Add the folders containing the utilities and the distribution to the
PATH
variable. To do this:- Click Start and type Change system environment variables in the Windows search bar.
- Click Environment Variables... at the bottom right.
- In the window that opens, find the
PATH
parameter and click Edit. - Add paths to the directories with the utilities to the list.
- Click OK.
Create a service account
- In the management console
, select the folder to create a service account in. - At the top of the screen, go to the Service accounts tab.
- At the top right, click Create service account.
- In the Name field, specify
sa-win-disk-connect
. - Click
Add role and select thestorage.editor
role. - Click Create service account.
If you do not 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.
Create a service account named sa-win-disk-connect
:
yc iam service-account create --name sa-win-disk-connect
The name format requirements are as follows:
- The name must be from 3 to 63 characters long.
- It may contain lowercase Latin letters, numbers, and hyphens.
- The first character must be a letter and the last character cannot be a hyphen.
For more information about the yc iam service-account create
command, see the CLI reference.
To create the service account, use the create method for the ServiceAccount resource.
Create a static access key
- In the management console
, navigate to the folder the service account belongs to. - At the top of the screen, go to the Service accounts tab.
- Select the
sa-win-disk-connect
service account. - In the top panel, click
Create new key. - Select Create static access key.
- Specify the key description and click Create.
- Save the ID and private key. After you close the dialog, the private key value will become unavailable.
-
Create an access key for the
sa-win-disk-connect
service account:yc iam access-key create --service-account-name sa-win-disk-connect
Result:
access_key: id: aje6t3vsbj8l******** service_account_id: ajepg0mjt06s******** created_at: "2022-07-18T14:37:51Z" key_id: 0n8X6WY6S24N7Oj***** secret: JyTRFdqw8t1kh2-OJNz4JX5ZTz9Dj1rI9hx*****
For more information about the
yc iam access-key create
command, see the CLI reference. -
Save the
key_id
and thesecret
key. You will not be able to get the key value again.
Create a bucket
- In the management console
, select the folder you want to create a bucket in. - In the list of services, select Object Storage.
- At the top right, click Create bucket.
- In the ** Name** field, enter a name for the bucket consistent with the naming conventions.
- In the Object read access, Object listing access, and Read access to settings fields, select Restricted.
- Click Create bucket.
-
If you do not have the AWS CLI yet, install and configure it.
-
Enter the bucket name following the naming conventions:
aws --endpoint-url https://storage.yandexcloud.net \ s3 mb s3://<bucket_name>
Result:
make_bucket: <bucket_name>
Note
Terraform uses a service account to interact with Object Storage. Assign to the service account the required role, e.g., storage.admin
, for the folder where you are going to create resources.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
Describe the parameters for creating a service account and access key in the configuration file:
... // Creating a service account resource "yandex_iam_service_account" "sa" { name = "<service_account_name>" } // Assigning a role to a service account resource "yandex_resourcemanager_folder_iam_member" "sa-admin" { folder_id = "<folder_ID>" role = "storage.admin" member = "serviceAccount:${yandex_iam_service_account.sa.id}" } // Creating a static access key resource "yandex_iam_service_account_static_access_key" "sa-static-key" { service_account_id = yandex_iam_service_account.sa.id description = "static access key for object storage" }
-
Add a section with bucket parameters to the configuration file and enter the bucket name following the naming conventions:
resource "yandex_storage_bucket" "<bucket_name>" { access_key = yandex_iam_service_account_static_access_key.sa-static-key.access_key secret_key = yandex_iam_service_account_static_access_key.sa-static-key.secret_key bucket = "<bucket_name>" }
For more information about the
yandex_storage_bucket
resource, see the Terraform provider documentation . -
Make sure the configuration files are correct.
-
In the command line, go to the folder where you created the configuration file.
-
Run a check using this command:
terraform plan
If the configuration is described correctly, the terminal will display a list of created resources and their parameters. If the configuration contains any errors, Terraform will point them out.
-
-
Deploy cloud resources.
-
If the configuration does not contain any errors, run this command:
terraform apply
-
Confirm creating the resources: type
yes
in the terminal and press Enter.
-
Use the create REST API method for the Bucket resource, the BucketService/Create gRPC API call, or the create S3 API method.
Set up a connection to Object Storage
-
Open the command line in your working folder as an admin user and run the following command:
.\psexec -i -s cmd.exe
-
In the console that opens, run
whoami
and make sure the session has been started by the system user. -
Go to the folder with the
rclone
utility and run its configuration session:rclone.exe config
-
Follow the prompts to create a new connection profile:
- Start creating a new profile by entering
n
in the terminal. - Enter the connection name:
s3-connect
. - Select the storage type by entering
4
in the terminal. - Select a provider by entering
1
in the terminal. - Select manual entry of credentials by entering
1
in the terminal. - Enter the secret key ID in the terminal.
- Enter the secret key value in the terminal.
- Specify the region by entering
ru-central1
in the terminal. - Specify the endpoint by entering
storage.yandexcloud.net
in the terminal. - You can leave all other settings at their defaults by pressing Enter to skip them.
- Start creating a new profile by entering
Note
You can perform advanced connection setup if needed. To do this, type y
at the Edit advanced config?
step. For more information about advanced settings, see the rclone
documentation
Mount a bucket
-
Check your connection to the bucket. In the same command line you used to configure the connection, run the following command with the bucket name specified:
rclone.exe ls s3-connect:<bucket_name>
If the configuration is set up correctly, the objects in the bucket will be listed in the console.
-
Mount the bucket to the file system specifying the bucket name and an available drive letter in the file system:
rclone.exe mount s3-connect:<bucket_name> <disk_letter>: --vfs-cache-mode full
You will see a new disk with the objects from the bucket in Windows Explorer.
-
To mount the bucket, press Ctrl + C.
Set up the mounting service
To mount the bucket at your desktop startup, set up mounting on behalf of the system service.
-
In the
WinSW
utility folder, create a file namedWinSW-x64.xml
(WinSW-x86.xml
if you have a 32-bit version of Windows) with the following contents:<service> <id>rclone</id> <name>rclone-s3-disk</name> <description>This service maps an S3 bucket as a system drive.</description> <executable>"<working_folder_location>\rclone.exe"</executable> <arguments>mount s3-connect:<bucket_name> <disk_letter>: --vfs-cache-mode full</arguments> <log mode="roll" /> <onfailure action="restart" /> </service>
-
In the same folder, open the command prompt as an admin user and run the following command:
-
If you have a 64-bit version of Windows:
.\WinSW-x64.exe install .\WinSW-x64.xml
-
If you have a 32-bit version of Windows:
.\WinSW-x86.exe install .\WinSW-x86.xml
-
-
Open the Windows services panel and make sure
rclone-s3-disk
is listed:- Press Win+R.
- In the window that opens, enter
services.msc
and click ОК. - In the list of services, find
rclone-s3-disk
.
-
Reboot your desktop and check that the disk is available.
Note
You can also configure the service to be run by a system user (for more information, see Service accountWinSW
utility documentation).
How to delete the resources you created
To stop paying for the resources you created:
- Delete the objects from the bucket.
- Delete the bucket.