[Yandex Cloud documentation](../../../index.md) > [Yandex Object Storage](../../index.md) > [Step-by-step guides](../index.md) > Buckets > Managing bucket labels

# Managing bucket labels

A [bucket label](../../concepts/tags.md) is a key-value pair used for logical bucket labeling.

{% note info %}

Yandex Cloud uses _labels_ to logically identify resources. However, Object Storage supports compatibility with [Amazon S3 API](https://docs.aws.amazon.com/AmazonS3/latest/API/Welcome.html), that is why we use _tags_, a term native to AWS, in the [AWS CLI](../../tools/aws-cli.md) commands and [API](../../s3/index.md) parameters.

{% endnote %}

## Adding or updating labels {#add-edit-tag}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select a folder.
  1. Navigate to **Object Storage**.
  1. Select the bucket where you want to add or change labels.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/wrench.svg) **Settings**.
  1. Select the **General** tab.
  1. Click **Add label**.
  1. Enter a label in `key: value` format. To update an existing label, enter its key and a new value.
  1. Press **Enter**.
  1. Click **Save**.

- Yandex Cloud CLI {#cli}

  {% note warning %}
  
  Updating the bucket settings will completely overwrite the existing labels.
  
  {% endnote %}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. See the description of the CLI command for updating bucket settings:

       ```bash
       yc storage bucket update --help
       ```

  1. Get a list of buckets in the default folder:

      ```bash
      yc storage bucket list
      ```

      Result:

      ```text
      +------------------+----------------------+----------+-----------------------+---------------------+
      |       NAME       |      FOLDER ID       | MAX SIZE | DEFAULT STORAGE CLASS |     CREATED AT      |
      +------------------+----------------------+----------+-----------------------+---------------------+
      | my-bucket        | b1gmit33ngp3******** | 10       | STANDARD              | 2022-12-16 13:58:18 |
      +------------------+----------------------+----------+-----------------------+---------------------+
      ```

  1. Add labels, specifying the name of the bucket in question:

      ```bash
      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 parameter to list bucket labels in `key=value` format.

      Result:

      ```text
      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
      ```

- AWS CLI {#aws-cli}

  {% note warning %}
  
  Updating the bucket settings will completely overwrite the existing labels.
  
  {% endnote %}

  If you do not have the AWS CLI yet, [install and configure it](../../tools/aws-cli.md).

  In the terminal, run this command:

  ```bash
  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, the `string` type.
    * `Value`: Label value, the `string` type.
  * `--endpoint-url`: Object Storage endpoint.

- Terraform {#tf}

  {% note warning %}
  
  Updating the bucket settings will completely overwrite the existing labels.
  
  {% endnote %}

  {% note info %}
  
  If you access Object Storage via Terraform under a [service account](../../../iam/concepts/users/service-accounts.md), [assign](../../../iam/operations/sa/assign-role-for-sa.md) to the service account the relevant [role](../../security/index.md#roles-list), e.g., `storage.admin`, for the folder you are going to create the resources in.
  
  {% endnote %}

  With [Terraform](https://www.terraform.io/), you can quickly create a cloud infrastructure in Yandex Cloud and manage it using configuration files. These files store the infrastructure description written in HashiCorp Configuration Language (HCL). If you change the configuration files, Terraform automatically detects which part of your configuration is already deployed, and what should be added or removed.
  
  Terraform is distributed under the [Business Source License](https://github.com/hashicorp/terraform/blob/main/LICENSE). The [Yandex Cloud provider for Terraform](https://github.com/yandex-cloud/terraform-provider-yandex) is distributed under the [MPL-2.0](https://www.mozilla.org/en-US/MPL/2.0/) license.
  
  For more information about the provider resources, see the guides on the [Terraform](https://www.terraform.io/docs/providers/yandex/index.html) website or [its mirror](../../../terraform/index.md).

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.


  1. Open the Terraform configuration file and add the `tags` section to the bucket description:

      ```hcl
      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 the array of bucket labels in `<key> = "<value>"` format.

      For more information on the properties of the `yandex_storage_bucket` resource in Terraform, see [this provider guide](../../../terraform/resources/storage_bucket.md).

  1. Apply the changes:

      1. In the terminal, navigate to the configuration file directory.
      1. Make sure the configuration is correct using this command:
      
         ```bash
         terraform validate
         ```
      
         If the configuration is valid, you will get this message:
      
         ```bash
         Success! The configuration is valid.
         ```
      
      1. Run this command:
      
         ```bash
         terraform plan
         ```
      
         You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
      1. Apply the configuration changes:
      
         ```bash
         terraform apply
         ```
      
      1. Type `yes` and press **Enter** to confirm the changes.

  This will add the specified labels to your bucket. You can check the new labels and the bucket settings using the [management console](https://console.yandex.cloud) or this [CLI](../../../cli/quickstart.md) command:

  ```bash
  yc storage bucket get <bucket_name> --full
  ```

- API {#api}

  {% note warning %}
  
  Updating the bucket settings will completely overwrite the existing labels.
  
  {% endnote %}

  To add or update bucket labels, use the [update](../../api-ref/Bucket/update.md) REST API method for the [Bucket](../../api-ref/Bucket/index.md) resource, the [BucketService/Update](../../api-ref/grpc/Bucket/update.md) gRPC API call, or the [putBucketTagging](../../s3/api-ref/bucket/putbuckettagging.md) S3 API method.

  **Example of a gRPC API call**

  ```bash
  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](../../../iam/concepts/authorization/iam-token.md).
  * `name`: Bucket name.
  * `update_mask`: List of bucket parameters you want to update.
  * `tags`: List of bucket labels.
  * `key`: Label key.
  * `value`: Label value.

  Result:

  ```json
  {
    "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"}
  }
  ```

{% endlist %}

## Viewing labels {#get-tag}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select a folder.
  1. Navigate to **Object Storage**.
  1. Select the bucket from the list.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/wrench.svg) **Settings**.
  1. Select the **General** tab.

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. See the description of the CLI command for getting bucket information:

      ```bash
      yc storage bucket get --help
      ```

  1. Get a list of buckets in the default folder:

      ```bash
      yc storage bucket list
      ```

      Result:

      ```text
       +------------------+----------------------+----------+-----------------------+---------------------+
       |       NAME       |      FOLDER ID       | MAX SIZE | DEFAULT STORAGE CLASS |     CREATED AT      |
       +------------------+----------------------+----------+-----------------------+---------------------+
       | my-bucket        | b1gmit33ngp3******** | 10       | STANDARD              | 2022-12-16 13:58:18 |
       +------------------+----------------------+----------+-----------------------+---------------------+
      ```

  1. Get information about the labels, specifying the name of the bucket in question:

      ```bash
      yc storage bucket get <bucket_name> --full
      ```

      Result:

      ```text
      name: my-bucket
      folder_id: b1gmit33ngp3********
      default_storage_class: STANDARD
      ...
      tags:
        - key: key-tag
          value: key-value
      ...
      ```

- AWS CLI {#aws-cli}

  If you do not have the AWS CLI yet, [install and configure it](../../tools/aws-cli.md).

  In the terminal, run this command:

  ```bash
  aws s3api get-bucket-tagging \
    --bucket <bucket_name> \
    --endpoint-url=https://storage.yandexcloud.net
  ```

  Where:
  * `--bucket`: Bucket name.
  * `--endpoint-url`: Object Storage endpoint.

  Result:

  ```json
  {
      "TagSet": [
          {
              "Key": "test-key-1",
              "Value": "test-value-1"
          },
          {
              "Key": "test-key-2",
              "Value": "test-value-2"
          }
      ]
  }
  ```

- API {#api}

  To view bucket labels, use the [get](../../api-ref/Bucket/get.md) REST API method for the [Bucket](../../api-ref/Bucket/index.md) resource, the [BucketService/Get](../../api-ref/grpc/Bucket/get.md) gRPC API call, or the [getBucketTagging](../../s3/api-ref/bucket/getbuckettagging.md) S3 API method.

  **Example of a gRPC API call**

  ```bash
  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](../../../iam/concepts/authorization/iam-token.md).
  * `name`: Bucket name.
  * `view`: Scope of information provided (`VIEW_FULL` means full information about the bucket).
 
  Result:

  ```json
  {
    "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"
      }
    ]
  }
  ```

{% endlist %}

## Deleting labels {#delete-tag}

{% list tabs group=instructions %}

- Management console {#console}

  1. In the [management console](https://console.yandex.cloud), select a folder.
  1. Navigate to **Object Storage**.
  1. Select the bucket from the list.
  1. In the left-hand panel, select ![image](../../../_assets/console-icons/wrench.svg) **Settings**.
  1. Select the **General** tab.
  1. Click ![image](../../../_assets/console-icons/xmark.svg) next to the label.
  1. Click **Save**.

- Yandex Cloud CLI {#cli}

  If you do not have the Yandex Cloud CLI yet, [install and initialize it](../../../cli/quickstart.md#install).

  The folder used by default is the one specified when [creating](../../../cli/operations/profile/profile-create.md) the CLI profile. To change the default folder, use the `yc config set folder-id <folder_ID>` command. You can also specify a different folder for any command using `--folder-name` or `--folder-id`. If you access a resource by its name, the search will be limited to the default folder. If you access a resource by its ID, the search will be global, i.e., through all folders based on access permissions.

  1. See the description of the CLI command for updating bucket settings:

      ```bash
      yc storage bucket update --help
      ```

  1. Get a list of buckets in the default folder:

      ```bash
      yc storage bucket list
      ```

      Result:

      ```text
      +------------------+----------------------+----------+-----------------------+---------------------+
      |       NAME       |      FOLDER ID       | MAX SIZE | DEFAULT STORAGE CLASS |     CREATED AT      |
      +------------------+----------------------+----------+-----------------------+---------------------+
      | my-bucket        | b1gmit33ngp3******** | 10       | STANDARD              | 2022-12-16 13:58:18 |
      +------------------+----------------------+----------+-----------------------+---------------------+
      ```

  1. Delete labels, specifying the name of the bucket in question:

      ```bash
      yc storage bucket update <bucket_name> \
        --remove-tags
      ```

      Result:

      ```text
      name: my-bucket
      folder_id: b1gmit33ngp3********
      default_storage_class: STANDARD
      versioning: VERSIONING_ENABLED
      acl: {}
      created_at: "2023-04-24T14:15:28.240705Z"
      ```

- AWS CLI {#aws-cli}

  If you do not have the AWS CLI yet, [install and configure it](../../tools/aws-cli.md).

  In the terminal, run this command:

  ```bash
  aws s3api delete-bucket-tagging \
    --bucket <bucket_name> \
    --endpoint-url=https://storage.yandexcloud.net
  ```

  Where:
  * `--bucket`: Bucket name.
  * `--endpoint-url`: Object Storage endpoint.

- Terraform {#tf}

  {% note info %}
  
  If you access Object Storage via Terraform under a [service account](../../../iam/concepts/users/service-accounts.md), [assign](../../../iam/operations/sa/assign-role-for-sa.md) to the service account the relevant [role](../../security/index.md#roles-list), e.g., `storage.admin`, for the folder you are going to create the resources in.
  
  {% endnote %}

  If you do not have Terraform yet, [install it and configure the Yandex Cloud provider](../../../tutorials/infrastructure-management/terraform-quickstart.md#install-terraform).
  
  
  To manage infrastructure using Terraform under a service account or user accounts (a Yandex account, a federated account, or a local user), [authenticate](../../../terraform/authentication.md) using the appropriate method.


  1. Open the Terraform configuration file and delete the `tags` section from the bucket description.

     {% cut "Example of a bucket label description in Terraform configuration" %}

      ```hcl
      resource "yandex_storage_bucket" "test-bucket" {
        bucket           = "<bucket_name>"
        ...
        tags             = {
          <label_1_key> = "<label_1_value>"
          <label_2_key> = "<label_2_value>"
        }
        ...
      }
      ```

     {% endcut %}

  1. Apply the changes:

      1. In the terminal, navigate to the configuration file directory.
      1. Make sure the configuration is correct using this command:
      
         ```bash
         terraform validate
         ```
      
         If the configuration is valid, you will get this message:
      
         ```bash
         Success! The configuration is valid.
         ```
      
      1. Run this command:
      
         ```bash
         terraform plan
         ```
      
         You will see a list of resources and their properties. No changes will be made at this step. Terraform will show any errors in the configuration.
      1. Apply the configuration changes:
      
         ```bash
         terraform apply
         ```
      
      1. Type `yes` and press **Enter** to confirm the changes.

  This will delete the bucket labels. You can check the label deletion and the bucket settings using the [management console](https://console.yandex.cloud) or this [CLI](../../../cli/quickstart.md) command:

  ```bash
  yc storage bucket get <bucket_name> --full
  ```

- API {#api}

  To delete bucket labels, use the [update](../../api-ref/Bucket/update.md) REST API method for the [Bucket](../../api-ref/Bucket/index.md) resource, the [BucketService/Update](../../api-ref/grpc/Bucket/update.md) gRPC API call, or the [deleteBucketTagging](../../s3/api-ref/bucket/deletebuckettagging.md) S3 API method.

  **Example of a gRPC API call**

  ```bash
  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](../../../iam/concepts/authorization/iam-token.md).
  * `name`: Bucket name.
  * `update_mask`: List of bucket parameters you want to update.
  * `tags`: List of bucket labels.

  Result:

  ```json
  {
    "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"}
  }
  ```

{% endlist %}