File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,15 +14,22 @@ if [ -z "$BUCKET_NAME" ] || [ "$BUCKET_NAME" = "None" ]; then
1414fi
1515
1616echo " Bucket: $BUCKET_NAME "
17-
18- # Empty the bucket (including versions)
19- OBJ_COUNT=$( aws s3api list-objects-v2 --bucket " $BUCKET_NAME " --query ' KeyCount' --output text 2> /dev/null || echo " 0" )
20- if [ " $OBJ_COUNT " -gt 0 ] 2> /dev/null; then
21- echo " Emptying $OBJ_COUNT objects..."
22- aws s3 rm " s3://$BUCKET_NAME " --recursive --quiet
17+ echo " "
18+ echo " Contents:"
19+ aws s3 ls " s3://$BUCKET_NAME /" 2> /dev/null || echo " (empty)"
20+ echo " "
21+ echo " This will permanently delete all objects and the bucket itself."
22+ read -rp " Type the bucket name to confirm: " CONFIRM
23+
24+ if [ " $CONFIRM " != " $BUCKET_NAME " ]; then
25+ echo " Bucket name does not match. Aborting."
26+ exit 1
2327fi
2428
25- # Delete versions and delete markers
29+ echo " "
30+ echo " Emptying bucket..."
31+ aws s3 rm " s3://$BUCKET_NAME " --recursive --quiet
32+
2633aws s3api list-object-versions --bucket " $BUCKET_NAME " \
2734 --query ' {Objects: Versions[].{Key:Key,VersionId:VersionId}, Quiet: true}' \
2835 --output json 2> /dev/null | \
You can’t perform that action at this time.
0 commit comments