Skip to content

Commit 1671007

Browse files
committed
Add bucket name confirmation to cleanup-bucket.sh
1 parent 7cb274a commit 1671007

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

cfn/cleanup-bucket.sh

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@ if [ -z "$BUCKET_NAME" ] || [ "$BUCKET_NAME" = "None" ]; then
1414
fi
1515

1616
echo "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
2327
fi
2428

25-
# Delete versions and delete markers
29+
echo ""
30+
echo "Emptying bucket..."
31+
aws s3 rm "s3://$BUCKET_NAME" --recursive --quiet
32+
2633
aws s3api list-object-versions --bucket "$BUCKET_NAME" \
2734
--query '{Objects: Versions[].{Key:Key,VersionId:VersionId}, Quiet: true}' \
2835
--output json 2>/dev/null | \

0 commit comments

Comments
 (0)