Object label management
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 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 of thestring
typeValue
: Label value of 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 fragment describing the object:resource "yandex_storage_object" "test-object" { access_key = "<static_key_ID>" secret_key = "<secret_key>" bucket = "<bucket_name>" key = "<object_name>" source = "<file_path>" tags = { <key_of_label_1> = "<value_of_label_1>" <key_of_label_2> = "<value_of_label_2>" } }
Where
tags
is an array of object labels in<key> = "<value>"
format.For more information about the
yandex_storage_object
resource parameters 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 object. You can check the new labels and the object's configuration using the AWS CLI or S3 API.
To add or edit object labels, use the putObjectTagging S3 API method.
Viewing labels
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 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 fragment describing the object.Sample object tag description in a Terraform configuration
resource "yandex_storage_object" "test-object" { ... tags = { <key_of_label_1> = "<value_of_label_1>" <key_of_label_2> = "<value_of_label_2>" } } ...
-
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 object's labels. You can check the deletion of labels and the object's configuration using the AWS CLI or S3 API.
To delete object labels, use the deleteObjectTagging S3 API method.