Deleting a bucket
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.
To delete a bucket that stores the logs of another bucket, go to the source bucket settings to disable logging or select a different target bucket for storing logs.
- In the management console
, select a folder. - Go to Object Storage.
- Select the bucket in question, click
, and select Delete. - In the window that opens, click 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 a bucket:
yc storage bucket delete --help -
Get a list of buckets in the default folder:
yc storage bucket listResult:
+------------------+----------------------+-------------+-----------------------+---------------------+ | NAME | FOLDER ID | MAX SIZE | DEFAULT STORAGE CLASS | CREATED AT | +------------------+----------------------+-------------+-----------------------+---------------------+ | first-bucket | b1gmit33ngp6******** | 53687091200 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+-------------+-----------------------+---------------------+ -
Save the name (from the
NAMEcolumn) of the bucket you are going to delete. -
Delete the bucket:
yc storage bucket delete --name <bucket_name>Where
--nameis the name of the bucket to delete.
If you do not have the AWS CLI yet, install and configure it.
In the terminal, run the aws s3api delete-bucket command:
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:
aws --endpoint-url=https://storage.yandexcloud.net \
s3 rb s3://<bucket_name>
To simultaneously delete multiple buckets, run this command:
Note
You can authorize in the Amazon S3 HTTP API and tools that support it using static keys obtained for the service account.
You can only view the list of buckets in the folder in which your service account was created.
-
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
--queryis the query in JMESPath format.Here is an example of a command that deletes all buckets whose names start with
samplebucket: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:
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
--queryis the query in JMESPath format.Here is an example of a command that deletes all buckets whose names start with
samplebucket: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}
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.
With Terraform
Terraform is distributed under the Business Source License
For more information about the provider resources, see the relevant documentation on the Terraform
If you do not have Terraform yet, install it and configure the Yandex Cloud provider.
To delete a bucket created with Terraform:
-
Open the Terraform configuration file and delete the section with the bucket description.
Example of a bucket description in Terraform configuration
... resource "yandex_storage_bucket" "test" { access_key = "YCAJEX9Aw2ge********-w-lJ" secret_key = "YCONxG7rSdz********_NRy5VbKzKlqZ********" bucket = "<bucket_name>" } ... -
In the command line, navigate to the directory with the Terraform configuration file.
-
Check the configuration using this command:
terraform validateIf the configuration is correct, you will get this message:
Success! The configuration is valid. -
Run this command:
terraform planYou 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 -
Confirm the changes: type
yesinto the terminal and press Enter.You can check the update using the management console
.
To delete a bucket, use the delete REST API method for the Bucket resource, the BucketService/Delete gRPC API call, or the deleteBucket S3 API method.