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 Object Storage from the list of services. - 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 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 a bucket:
yc storage bucket delete --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 | +------------------+----------------------+-------------+-----------------------+---------------------+ | first-bucket | b1gmit33ngp6******** | 53687091200 | STANDARD | 2022-12-16 13:58:18 | +------------------+----------------------+-------------+-----------------------+---------------------+
-
Save the name (from the
NAME
column) of the bucket you are going to delete. -
Delete the bucket:
yc storage bucket delete --name <bucket_name>
Where
--name
is 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 directory in which the service account you are using 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
--query
is 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
--query
is 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 documentation on the Terraform
If you don't have Terraform, 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, go to the directory with the Terraform configuration file.
-
Check the configuration using this command:
terraform validate
If the configuration is correct, you will get this message:
Success! The configuration is valid.
-
Run this command:
terraform plan
The terminal will display a list of resources with their parameters. No changes will be made at this step. If the configuration contains any errors, Terraform will point them out.
-
Apply the configuration changes:
terraform apply
-
Confirm the changes: type
yes
into 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.