Deleting a bucket
Warning
You can delete only 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 the bucket that stores the logs of another bucket, go to the source bucket settings to disable logging or select another target bucket for storing logs.
- In the management console
, select Object Storage from the list of services. - Select the bucket you need and click
→ Delete. - In the window that opens, click Delete.
If you do not have the Yandex Cloud command line interface yet, install and initialize it.
The folder specified in the CLI profile is used by default. You can specify a different folder using the --folder-name
or --folder-id
parameter.
-
See the description of the CLI command to delete 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 | +------------------+----------------------+-------------+-----------------------+---------------------+
-
Use the
NAME
column to save the name 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.
You can also 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.Example of the command for deleting 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.Example of the command for deleting 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 fragment describing the bucket.
Example bucket description in a 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 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 changes in 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.