Managing object labels
An object label is a key-value pair used for logical object labeling.
Note
Yandex Cloud uses labels to logically identify resources. However, Object Storage supports compatibility 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 you need. - In the left-hand panel, select
Objects. - Click the name of the object you need.
- Click Add label.
- Enter label key and value separated by a colon (key:value).
To edit a label:
- Click Add label.
- Enter the key of the label you want to edit and its new value.
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.
-
See the description of the CLI command for updating object labels in a bucket:
yc storage s3api put-object-tagging --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 | b1g5dk66rc1u******** | 53687091200 | STANDARD | 2024-12-17 07:17:04 | +------------------+----------------------+-------------+-----------------------+---------------------+
-
In the terminal, run this command that overwrites any existing object labels:
yc storage s3api put-object-tagging \ --bucket <bucket_name> \ --key <object_key> \ --version-id <version_ID> \ --tagging TagSet=[{Key=<label_key>,Value=<label_value>},{Key=<label_key>,Value=<label_value>}]
Where:
--bucket
: Bucket name.--key
: Bucket object key.--version-id
: Object version. This is an optional parameter.--tagging
: Array of object labels, where:Key
: Label key, thestring
type.Value
: Label value, thestring
type.
Result:
request_id: ac9066e5********
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run this command that overwrites any existing object labels:
aws s3api put-object-tagging \
--bucket <bucket_name> \
--key <object_key> \
--tagging 'TagSet=[{Key=<label_key>,Value=<label_value>},{Key=<label_key>,Value=<label_value>}]' \
--endpoint-url=https://storage.yandexcloud.net
Where:
--bucket
: Bucket name.--key
: Bucket object key.--tagging
: Array of object labels, where:Key
: Label key, thestring
type.Value
: Label value, thestring
type.
--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 do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and add the
tags
section to the object description:resource "yandex_storage_object" "test-object" { access_key = "<static_key_ID>" secret_key = "<secret_key>" bucket = "<bucket_name>" key = "<object_name>" source = "<path_to_file>" tags = { <label_1_key> = "<label_1_value>" <label_2_key> = "<label_2_value>" } }
Where
tags
is the array of object labels in<key> = "<value>"
format.For more information about the
yandex_storage_object
resource in Terraform, see this TF provider article . -
Apply the changes:
-
In the terminal, go to the directory where you edited the configuration file.
-
Make sure the configuration file is correct using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
You will see a detailed list of resources. No changes will be made at this step. If the configuration contains any errors, Terraform will show them.
-
Apply the changes:
terraform apply
-
Type
yes
and press Enter to confirm the changes.
-
This will add the specified labels to your object. You can check the new labels and the object settings using the AWS CLI or S3 API.
To add or update object labels, use the putObjectTagging S3 API method.
Viewing labels
You can see the labels in the list of bucket objects and on the individual object's page.
- In the management console
, select Object Storage from the list of services and go to the bucket in question. - In the left-hand panel, select
Objects. - Click the name of the object you need.
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.
-
See the description of the CLI command for viewing object labels in a bucket:
yc storage s3api get-object-tagging --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 | b1g5dk66rc1u******** | 53687091200 | STANDARD | 2024-12-17 07:17:04 | +------------------+----------------------+-------------+-----------------------+---------------------+
-
Get information about object labels:
yc storage s3api get-object-tagging \ --bucket <bucket_name> \ --key <object_key> \ --version-id <version_ID>
Where:
--bucket
: Bucket name.--key
: Bucket object key.--version-id
: Object version. This is an optional parameter.
Result:
request_id: 2defc7b2******** tag_set: - key: key-for-my-object-2 value: second-value - key: key-for-my-object-1 value: first-value
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run this command:
aws s3api get-object-tagging \
--bucket <bucket_name> \
--key <object_key> \
--endpoint-url=https://storage.yandexcloud.net
Where:
--bucket
: Bucket name.--key
: Bucket object key.--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 object labels, use the getObjectTagging S3 API method.
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
Objects. - Click the name of the object you need.
- Click the cross next to the label you want to delete.
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.
-
See the description of the CLI command for deleting object labels in a bucket:
yc storage s3api delete-object-tagging --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 | b1g5dk66rc1u******** | 53687091200 | STANDARD | 2024-12-17 07:17:04 | +------------------+----------------------+-------------+-----------------------+---------------------+
-
Delete object labels from the bucket:
yc storage s3api delete-object-tagging \ --bucket <bucket_name> \ --key <object_key> \ --version-id <version_ID>
Where:
--bucket
: Bucket name.--key
: Bucket object key.--version-id
: Object version. This is an optional parameter.
Result:
request_id: 1131dfc4********
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run this command:
aws s3api delete-object-tagging \
--bucket <bucket_name> \
--key <object_key> \
--endpoint-url=https://storage.yandexcloud.net
Where:
--bucket
: Bucket name.--key
: Bucket object key.--endpoint-url
: Object Storage endpoint.
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
-
Open the Terraform configuration file and delete the
tags
section from the object description.Example of an object label description in Terraform configuration
resource "yandex_storage_object" "test-object" { ... tags = { <label_1_key> = "<label_1_value>" <label_2_key> = "<label_2_value>" } } ...
-
Apply the changes:
-
In the terminal, go to the directory where you edited the configuration file.
-
Make sure the configuration file is correct using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
You will see a detailed list of resources. No changes will be made at this step. If the configuration contains any errors, Terraform will show them.
-
Apply the changes:
terraform apply
-
Type
yes
and press Enter to confirm the changes.
-
This will delete the object labels. You can check the label deletion and the object settings using the AWS CLI or S3 API.
To delete object labels, use the deleteObjectTagging S3 API method.