Versioned Bucket Delete All Objects and bucket

0

If I have a bucket that is versioned. What CLI command can delete all versions of all objects as well as the bucket? I ran the aws s3 rm command but it did not delete all versions of the objects.

Thanks

質問済み 2ヶ月前230ビュー
1回答
1
承認された回答

Hello.

You cannot delete versioned bucket objects in bulk using the AWS CLI, so you need to create a shell script as shown below.
However, while this method works if there are few objects, if there are tens of thousands of objects, I think it is easier to set up lifecycle rules to delete them.
https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-lifecycle-mgmt.html

bucket=hoge-bucket && aws s3api list-object-versions --bucket $bucket | jq -r '.Versions[] | [.Key, .VersionId] |@tsv' | while read k v;do aws s3api delete-object --bucket $bucket --key $k --version-id $v; done
profile picture
エキスパート
回答済み 2ヶ月前
profile picture
エキスパート
レビュー済み 2ヶ月前
profile picture
エキスパート
レビュー済み 2ヶ月前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ