Skip to content

Commit

Permalink
updated aws_s3_delete_bucket_with_versions.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
HariSekhon committed Dec 11, 2024
1 parent 7c02bab commit 7f4a3a5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions aws/aws_s3_delete_bucket_with_versions.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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="$(
Expand All @@ -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"
Expand Down

0 comments on commit 7f4a3a5

Please sign in to comment.