Last active
November 8, 2023 14:33
-
-
Save WarFox/0b551c794b30b5e50496103410abf98c to your computer and use it in GitHub Desktop.
List empty S3 buckets
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
echo "Index,Bucket Name,Status,Repository,Created By" | |
counter=count | |
count=0 | |
for b in $(aws s3 ls | cut -d" " -f3) | |
do | |
if [[ "$(aws s3api list-objects-v2 --bucket $b --max-items 1)" == "" ]] | |
then | |
(($counter++)) | |
echo -n $count,$b",BUCKET EMPTY," | |
tags="$(aws s3api get-bucket-tagging --bucket $b --query 'TagSet[?Key==`Repository` || Key == `Created_by`].Value' | jq -r '@csv')" | |
echo $tags | |
fi | |
done |
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
for b in $(aws s3 ls | cut -d" " -f3) | |
do | |
if [[ "$(aws s3api list-objects-v2 --bucket $b --max-items 1)" == "" ]] | |
then | |
echo -n "|" $b "| BUCKET EMPTY |" | |
tags="$(aws s3api get-bucket-tagging --bucket $b --query 'TagSet[?Key==`Repository` || Key == `CreatedBy`].Value' | jq -r '@csv' | sed 's/\",\"/\" | \"/g')" | |
echo $tags " |" | |
fi | |
done | |
# Here the Repository and CreatedBy tags will be shown along with the bucket name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment