How do I delete a versioned bucket in AWS S3 using the CLI?

前端 未结 20 929
我在风中等你
我在风中等你 2020-12-07 16:34

I have tried both s3cmd:

$ s3cmd -r -f -v del s3://my-versioned-bucket/

And the AWS CLI:

$ aws s3 rm s3://my-v         


        
20条回答
  •  攒了一身酷
    2020-12-07 16:46

    If you have to delete/empty large S3 buckets, it becomes quite inefficient (and expensive) to delete every single object and version. It's often more convenient to let AWS expire all objects and versions.

    aws s3api put-bucket-lifecycle-configuration \
      --lifecycle-configuration '{"Rules":[{
          "ID":"empty-bucket",
          "Status":"Enabled",
          "Prefix":"",
          "Expiration":{"Days":1},
          "NoncurrentVersionExpiration":{"NoncurrentDays":1}
        }]}' \
      --bucket YOUR-BUCKET
    

    Then you just have to wait 1 day and the bucket can be deleted with:

    aws s3api delete-bucket --bucket YOUR-BUCKET
    

提交回复
热议问题