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

# Deleting a bucket

{% note warning %}

You can only delete an empty bucket. In the management console, the information about the number of objects in the bucket is updated with a few minutes' delay.

{% endnote %}

To delete a bucket that [stores the logs](../../concepts/server-logs.md) of another bucket, go to the source bucket settings to [disable logging](enable-logging.md#stop-logging) or select a different target bucket for storing logs.

{% 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 in question, click ![image](../../../_assets/console-icons/ellipsis.svg), and select ![image](../../../_assets/console-icons/trash-bin.svg) **Delete**.
  1. In the window that opens, click **Delete**.

  {% note info %}
  
  It is more convenient to work with multiple buckets using the [CyberDuck](../../tools/cyberduck.md) and [WinSCP](../../tools/winscp.md) file browsers or the [AWS CLI](../../tools/aws-cli.md).
  
  {% endnote %}

- 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 deleting a bucket:

      ```bash
      yc storage bucket delete --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      |
     +------------------+----------------------+-------------+-----------------------+---------------------+
     | first-bucket     | b1gmit33ngp6******** | 53687091200 | STANDARD              | 2022-12-16 13:58:18 |
     +------------------+----------------------+-------------+-----------------------+---------------------+
     ```
  1. Save the name (from the `NAME` column) of the bucket you are going to delete.
  1. Delete the bucket:

      ```bash
      yc storage bucket delete --name <bucket_name>
      ```

      Where `--name` is the name of the bucket to delete.

      {% note info %}
      
      It is more convenient to work with multiple buckets using the [CyberDuck](../../tools/cyberduck.md) and [WinSCP](../../tools/winscp.md) file browsers or the [AWS CLI](../../tools/aws-cli.md).
      
      {% endnote %}

- 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 the `aws s3api delete-bucket` command:

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

  Where:
  * `--bucket`: Name of the bucket to delete.
  * `--endpoint-url`: Object Storage endpoint.

  Alternatively, you can use the `aws s3 rb` command:

  ```bash
  aws --endpoint-url=https://storage.yandexcloud.net \
    s3 rb s3://<bucket_name>
  ```

  To simultaneously delete multiple buckets, run this command:

  {% note info %}
  
  You can authorize in the [Amazon S3 HTTP API](../../s3/index.md) and [tools that support it](../../tools/index.md) using [static keys](../../../iam/concepts/authorization/access-key.md) obtained for the [service account](../../../iam/concepts/users/service-accounts.md).
  
  You can only view the list of buckets in the folder in which your service account was created.
  
  {% endnote %}

  * **Bash**:

    ```bash
    aws s3api list-buckets \
      --endpoint-url=https://storage.yandexcloud.net \
      --query '<query>' \
      --output text | xargs -I {} aws s3api delete-bucket --endpoint-url=https://storage.yandexcloud.net --bucket {}
    ```

    Where `--query` is the query in [JMESPath](https://jmespath.org/) format.

    Here is an example of a command that deletes all buckets whose names start with `samplebucket`:

    ```bash
    aws s3api list-buckets \
      --endpoint-url=https://storage.yandexcloud.net \
      --query 'Buckets[?starts_with(Name, `samplebucket`) == `true`].[Name]' \
      --output text | xargs -I {} aws s3api delete-bucket --endpoint-url=https://storage.yandexcloud.net --bucket {}
    ```

  * **PowerShell**:

    ```powershell
    Foreach($x in (aws s3api list-buckets `
      --endpoint-url=https://storage.yandexcloud.net `
      --query '<query>' `
      --output text)) `
      {aws s3api delete-bucket `
      --endpoint-url=https://storage.yandexcloud.net `
      --bucket $x}
    ```

    Where `--query` is the query in [JMESPath](https://jmespath.org/) format.

    Here is an example of a command that deletes all buckets whose names start with `samplebucket`:

    ```powershell
    Foreach($x in (aws s3api list-buckets `
      --endpoint-url=https://storage.yandexcloud.net `
      --query 'Buckets[?starts_with(Name, `samplebucket`) == `true`].[Name]' `
      --output text)) `
      {aws s3api delete-bucket `
      --endpoint-url=https://storage.yandexcloud.net `
      --bucket $x}
    ```

- 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 %}

  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 relevant documentation 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.



  To delete a bucket created with Terraform:
  1. Open the Terraform configuration file and delete the section with the bucket description.

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

     ```hcl
     ...
     resource "yandex_storage_bucket" "test" {
       access_key = "YCAJEX9Aw2ge********-w-lJ"
       secret_key = "YCONxG7rSdz********_NRy5VbKzKlqZ********"
       bucket     = "<bucket_name>"
     }
     ...
     ```

     {% 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.

     You can check the update using the [management console](https://console.yandex.cloud).

- API {#api}

  To delete a bucket, use the [delete](../../api-ref/Bucket/delete.md) REST API method for the [Bucket](../../api-ref/Bucket/index.md) resource, the [BucketService/Delete](../../api-ref/grpc/Bucket/delete.md) gRPC API call, or the [deleteBucket](../../s3/api-ref/bucket/delete.md) S3 API method.

  {% note info %}
  
  It is more convenient to work with multiple buckets using the [CyberDuck](../../tools/cyberduck.md) and [WinSCP](../../tools/winscp.md) file browsers or the [AWS CLI](../../tools/aws-cli.md).
  
  {% endnote %}

{% endlist %}