Bucket label management
A bucket label is a key-value pair used for logical bucket labeling.
Note
In Yandex Cloud terminology, we use the label concept to denote logical resource labeling. However, as Object Storage is compatible with Amazon S3 API
Adding or updating labels
- In the management console
, select Object Storage from the list of services and go to the bucket whose labels you need to add or edit. - In the left-hand panel, select
Settings. - Select the General tab.
- Click Add label.
- Enter a label in
key: value
format. To edit an existing label, enter its key and a new value. - Click Enter.
- Click Save.
Warning
Updating the bucket settings will completely overwrite the existing set of labels with the new one.
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.
-
View the description of the CLI command for changing the bucket settings:
yc storage bucket update --help
-
Get a list of buckets in the default folder:
yc storage bucket list
Result:
+------------------+----------------------+----------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+----------+-----------------------+---------------------+ | my-bucket | b1gmit33ngp3******** | 10 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+----------+-----------------------+---------------------+
-
Add labels by specifying the name of the required bucket:
yc storage bucket update <bucket_name> \ --tags <label_1_key>=<label_1_value>,<label_2_key>=<label_2_value>,...,<label_n_key>=<label_n_value>
Where
--tags
is a flag to list bucket labels inkey=value
format.Result:
name: my-bucket folder_id: b1gmit33ngp3******** default_storage_class: STANDARD versioning: VERSIONING_ENABLED acl: {} created_at: "2023-04-24T14:15:28.240705Z" tags: - key: key-tag value: key-value
Warning
Updating the bucket settings will completely overwrite the existing set of labels with the new one.
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run this command:
aws s3api put-bucket-tagging \
--bucket <bucket_name> \
--tagging 'TagSet=[{Key=<label_key>,Value=<label_value>},{Key=<label_key>,Value=<label_value>}]' \
--endpoint-url=https://storage.yandexcloud.net
Where:
--bucket
: Bucket name.--tagging
: Array of bucket labels, where:Key
: Label key, thestring
type.Value
: Label value, thestring
type.
--endpoint-url
: Object Storage endpoint.
Warning
Updating the bucket settings will completely overwrite the existing set of labels with the new one.
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.
Terraform
For more information about the provider resources, see the documentation on the Terraform
If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
If you don't have Terraform, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and add the
tags
section to the bucket description fragment:resource "yandex_storage_bucket" "test-bucket" { bucket = "<bucket_name>" ... tags = { <label_1_key> = "<label_1_value>" <label_2_key> = "<label_2_value>" } ... }
Where
tags
is an array of bucket labels formatted as<key> = "<value>"
.For more information about the
yandex_storage_bucket
resource in Terraform, see the provider documentation . -
Apply the changes:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
-
That will add the labels to the bucket. You can check the new labels and the bucket's settings using the management console
yc storage bucket get <bucket_name> --full
Warning
Updating the bucket settings will completely overwrite the existing set of labels with the new one.
To add or update bucket labels, use the update REST API method for the Bucket resource, the BucketService/Update gRPC API call, or the putBucketTagging S3 API method.
Sample gRPC API call
export IAM_TOKEN="<IAM_token>"
grpcurl \
-H "Authorization: Bearer $IAM_TOKEN" \
-d '{"name": "test-bucket", "update_mask": {"paths": ["tags"]}, "tags": [{"key": "test-key", "value": "test-value"}]}' \
storage.api.cloud.yandex.net:443 \
yandex.cloud.storage.v1.BucketService/Update
Where:
IAM_TOKEN
: IAM token.name
: Bucket name.update_mask
: List of bucket parameters to update.tags
: List of bucket labels.key
: Label key.value
: Label value.
Result:
{
"id": "e3e5fsr6076bo*******",
"description": "update bucket",
"createdAt": "2023-04-27T12:01:03.636597Z",
"createdBy": "ajelcjkv67arb*******",
"modifiedAt": "2023-04-27T12:01:03.636597Z",
"done": true,
"metadata": {"@type":"type.googleapis.com/yandex.cloud.storage.v1.UpdateBucketMetadata","name":"test-bucket"},
"response": {"@type":"type.googleapis.com/yandex.cloud.storage.v1.Bucket","acl":{},"createdAt":"2023-03-27T08:23:26.890770Z","defaultStorageClass":"STANDARD","folderId":"b1gsm0k26v1l2*******","maxSize":"53687091200","name":"test-bucket","tags":[{"key":"test-key","value":"test-value"}],"versioning":"VERSIONING_DISABLED"}
}
Viewing labels
- In the management console
, select Object Storage from the list of services and go to the bucket you need. - In the left-hand panel, select
Settings. - Select the General tab.
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.
-
See a description of the CLI command to get bucket information:
yc storage bucket get --help
-
Get a list of buckets in the default folder:
yc storage bucket list
Result:
+------------------+----------------------+----------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+----------+-----------------------+---------------------+ | my-bucket | b1gmit33ngp3******** | 10 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+----------+-----------------------+---------------------+
-
Get information about the labels by specifying the name of the required bucket:
yc storage bucket get <bucket_name> --full
Result:
name: my-bucket folder_id: b1gmit33ngp3******** default_storage_class: STANDARD ... tags: - key: key-tag value: key-value ...
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run this command:
aws s3api get-bucket-tagging \
--bucket <bucket_name> \
--endpoint-url=https://storage.yandexcloud.net
Where:
--bucket
: Bucket name.--endpoint-url
: Object Storage endpoint.
Result:
{
"TagSet": [
{
"Key": "test-key-1",
"Value": "test-value-1"
},
{
"Key": "test-key-2",
"Value": "test-value-2"
}
]
}
To view bucket labels, use the get REST API method for the Bucket resource, the BucketService/Get gRPC API call, or the getBucketTagging S3 API method.
Example of gRPC API call
export IAM_TOKEN="<IAM_token>"
grpcurl \
-H "Authorization: Bearer $IAM_TOKEN" \
-d '{"name": "test-bucket", "view": "VIEW_FULL"}' \
storage.api.cloud.yandex.net:443 \
yandex.cloud.storage.v1.BucketService/Get
Where:
IAM_TOKEN
: IAM token.name
: Bucket name.view
: Amount of information being provided (VIEW_FULL
means full information about the bucket).
Result:
{
"name": "test-bucket",
"folderId": "b1gsm0k26v1l2*******",
"anonymousAccessFlags": {
"read": true,
"list": true,
"configRead": true
},
"defaultStorageClass": "STANDARD",
"versioning": "VERSIONING_DISABLED",
"maxSize": "53687091200",
"acl": {
},
"createdAt": "2023-03-27T08:23:26.890770Z",
"websiteSettings": {
"redirectAllRequests": {
}
},
"tags": [
{
"key": "test-key",
"value": "test-value"
}
]
}
Deleting labels
- In the management console
, select Object Storage from the list of services and go to the bucket you need. - In the left-hand panel, select
Settings. - Select the General tab.
- Click
next to the appropriate label. - Click Save.
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.
-
View the description of the CLI command for changing the bucket settings:
yc storage bucket update --help
-
Get a list of buckets in the default folder:
yc storage bucket list
Result:
+------------------+----------------------+----------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+----------+-----------------------+---------------------+ | my-bucket | b1gmit33ngp3******** | 10 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+----------+-----------------------+---------------------+
-
Delete labels by specifying the name of the required bucket:
yc storage bucket update <bucket_name> \ --remove-tags
Result:
name: my-bucket folder_id: b1gmit33ngp3******** default_storage_class: STANDARD versioning: VERSIONING_ENABLED acl: {} created_at: "2023-04-24T14:15:28.240705Z"
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run this command:
aws s3api delete-bucket-tagging \
--bucket <bucket_name> \
--endpoint-url=https://storage.yandexcloud.net
Where:
--bucket
: Bucket name.--endpoint-url
: Object Storage endpoint.
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.
-
Open the Terraform configuration file and delete the
tags
section from the bucket description fragment.Example of a bucket tag description in the Terraform configuration
resource "yandex_storage_bucket" "test-bucket" { bucket = "<bucket_name>" ... tags = { <label_1_key> = "<label_1_value>" <label_2_key> = "<label_2_value>" } ... }
-
Apply the changes:
-
In the terminal, change to the folder where you edited the configuration file.
-
Make sure the configuration file is correct using the command:
terraform validate
If the configuration is correct, the following message is returned:
Success! The configuration is valid.
-
Run the command:
terraform plan
The terminal will display a list of resources with parameters. No changes are made at this step. If the configuration contains errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
in the terminal and press Enter.
-
That will delete the bucket's labels. You can check the deletion of labels and the bucket's settings using the management console
yc storage bucket get <bucket_name> --full
To delete bucket labels, use the update REST API method for the Bucket resource, the BucketService/Update gRPC API call, or the deleteBucketTagging S3 API method.
Example of gRPC API call
export IAM_TOKEN="<IAM_token>"
grpcurl \
-H "Authorization: Bearer $IAM_TOKEN" \
-d '{"name": "test-bucket", "update_mask": {"paths": ["tags"]}, "tags": []}' \
storage.api.cloud.yandex.net:443 \
yandex.cloud.storage.v1.BucketService/Update
Where:
IAM_TOKEN
: IAM token.name
: Bucket name.update_mask
: List of bucket parameters to update.tags
: List of bucket labels.
Result:
{
"id": "e3epc33apcche*******",
"description": "update bucket",
"createdAt": "2023-04-27T12:18:18.885391Z",
"createdBy": "ajelcjkv67arb*******",
"modifiedAt": "2023-04-27T12:18:18.885391Z",
"done": true,
"metadata": {"@type":"type.googleapis.com/yandex.cloud.storage.v1.UpdateBucketMetadata","name":"test-bucket-777"},
"response": {"@type":"type.googleapis.com/yandex.cloud.storage.v1.Bucket","acl":{},"createdAt":"2023-03-27T08:23:26.890770Z","defaultStorageClass":"STANDARD","folderId":"b1gsm0k26v1l2*******","maxSize":"53687091200","name":"test-bucket-777","versioning":"VERSIONING_DISABLED"}
}