Managing object labels
An object label is a key-value pair used for logical object 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
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through 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 don't have Terraform, 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, 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.
-
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
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through 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
If you do not have the Yandex Cloud CLI yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder through 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 don't have Terraform, 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, 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.
-
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.