-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
FaithKovi
committed
Aug 3, 2024
1 parent
730c136
commit 9b06f9a
Showing
2 changed files
with
30 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
# Exit immediately if a command exits with a non-zero status | ||
set -e | ||
|
||
# Define variables | ||
BUCKET_NAME="$1" | ||
AWS_REGION="$2" | ||
|
||
echo "Deleting all objects and versions from bucket $BUCKET_NAME in region $AWS_REGION" | ||
|
||
# Delete all objects | ||
aws s3 rm s3://$BUCKET_NAME --recursive --region $AWS_REGION | ||
|
||
# If versioning is enabled, delete all object versions | ||
aws s3api list-object-versions --bucket $BUCKET_NAME --region $AWS_REGION --query "Versions[].[Key,VersionId]" --output text | \ | ||
while read -r key version_id; do | ||
aws s3api delete-object --bucket $BUCKET_NAME --key "$key" --version-id "$version_id" --region $AWS_REGION | ||
done | ||
|
||
# If there are delete markers, delete them too | ||
aws s3api list-object-versions --bucket $BUCKET_NAME --region $AWS_REGION --query "DeleteMarkers[].[Key,VersionId]" --output text | \ | ||
while read -r key version_id; do | ||
aws s3api delete-object --bucket $BUCKET_NAME --key "$key" --version-id "$version_id" --region $AWS_REGION | ||
done | ||
|
||
echo "Bucket $BUCKET_NAME emptied." |