From 7f4a3a52b0e5fdc28215c158fb3e58de3f815fe5 Mon Sep 17 00:00:00 2001 From: Hari Sekhon Date: Wed, 11 Dec 2024 18:47:15 +0700 Subject: [PATCH] updated aws_s3_delete_bucket_with_versions.sh --- aws/aws_s3_delete_bucket_with_versions.sh | 24 +++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/aws/aws_s3_delete_bucket_with_versions.sh b/aws/aws_s3_delete_bucket_with_versions.sh index 3701ebdccad..7551aa72f07 100755 --- a/aws/aws_s3_delete_bucket_with_versions.sh +++ b/aws/aws_s3_delete_bucket_with_versions.sh @@ -49,11 +49,13 @@ object_versions="$( --output text )" -while read -r key versionId; do - timestamp "Deleting object '$key' version '$versionId'" - aws s3api delete-object --bucket "$bucket" --key "$key" --version-id "$versionId" -done <<< "$object_versions" -echo >&2 +if [ "$object_versions" != "None" ]; then + while read -r key versionId; do + timestamp "Deleting object '$key' version '$versionId'" + aws s3api delete-object --bucket "$bucket" --key "$key" --version-id "$versionId" + done <<< "$object_versions" + echo >&2 +fi timestamp "Getting object deletion markers for bucket: $bucket" object_deletion_markers="$( @@ -63,11 +65,13 @@ object_deletion_markers="$( --output text )" -while read -r key versionId; do - timestamp "Deleting object deletion marker '$key' version '$versionId'" - aws s3api delete-object --bucket "$bucket" --key "$key" --version-id "$versionId" -done <<< "$object_deletion_markers" -echo >&2 +if [ "$object_deletion_markers" != "None" ]; then + while read -r key versionId; do + timestamp "Deleting object deletion marker '$key' version '$versionId'" + aws s3api delete-object --bucket "$bucket" --key "$key" --version-id "$versionId" + done <<< "$object_deletion_markers" + echo >&2 +fi timestamp "Deleting bucket: $bucket" #aws s3api delete-bucket --bucket "$bucket"