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

前端 未结 20 943
我在风中等你
我在风中等你 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 17:05

    Here is a one liner you can just cut and paste into the command line to delete all versions and delete markers (it requires aws tools, replace yourbucket-name-backup with your bucket name)

    echo '#!/bin/bash' > deleteBucketScript.sh \
    && aws --output text s3api list-object-versions --bucket $BUCKET_TO_PERGE \
    | grep -E "^VERSIONS" |\
    awk '{print "aws s3api delete-object --bucket $BUCKET_TO_PERGE --key "$4" --version-id "$8";"}' >> \
    deleteBucketScript.sh && . deleteBucketScript.sh; rm -f deleteBucketScript.sh; echo '#!/bin/bash' > \
    deleteBucketScript.sh && aws --output text s3api list-object-versions --bucket $BUCKET_TO_PERGE \
    | grep -E "^DELETEMARKERS" | grep -v "null" \
    | awk '{print "aws s3api delete-object --bucket $BUCKET_TO_PERGE --key "$3" --version-id "$5";"}' >> \
    deleteBucketScript.sh && . deleteBucketScript.sh; rm -f deleteBucketScript.sh;
    

    then you could use:

    aws s3 rb s3://bucket-name --force

提交回复
热议问题