Skip to content

Commit 080c7c4

Browse files
committed
fix bucket cleaning bug
1 parent 001f429 commit 080c7c4

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

deployment/cleanup.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/bin/sh
2-
2+
#set -xv
33
BUCKET=$1
4+
# test if an s3 bucket exists and delete all objects and delete markers from it
5+
# if it does not exist, just print a message
6+
bucketExists=`aws s3api list-buckets --query "Buckets[].Name" | grep -w "$BUCKET" | wc -l`
47

5-
bucketExists=$(aws s3api head-bucket --bucket "$BUCKET" 2>/dev/null && echo "yes" || echo "no")
6-
echo "BucketExists: $bucketExists"
7-
if [ "$bucketExists" = "yes" ]
8+
if [ "$bucketExists" -eq 1 ]
89
then
910
objects=$(aws s3api list-object-versions --bucket "$BUCKET" --no-paginate --output=json --query='{Objects: Versions[].{Key:Key,VersionId:VersionId}}')
1011
count=$(awk '/"Objects": null/ {print}' <<< "$objects" | wc -l)

0 commit comments

Comments
 (0)