-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuckets_prune.sh
executable file
·29 lines (22 loc) · 1010 Bytes
/
buckets_prune.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
# This script deletes all objects in specified S3 buckets
# List of S3 buckets to delete objects from
BUCKETS=("anonymisation-fragments" "anonymisation-scripts" "blueprints-for-anonymisation" "anonymisation-dumps")
# Function to delete all objects in a given S3 bucket
delete_objects() {
BUCKET_NAME=$1
echo "Deleting objects from bucket: ${BUCKET_NAME}"
# Retrieve list of objects in the bucket
OBJECTS=$(aws s3api list-objects --bucket "${BUCKET_NAME}" --query 'Contents[].{Key: Key}' --output json)
# Delete each object in the list
for OBJECT in $(echo "${OBJECTS}" | jq -r '.[].Key'); do
aws s3api delete-object --bucket "${BUCKET_NAME}" --key "${OBJECT}"
echo "Deleted object: ${OBJECT}"
done
echo "All objects in bucket ${BUCKET_NAME} have been deleted."
}
# Iterate over the list of S3 buckets and call the delete_objects function
for BUCKET in "${BUCKETS[@]}"; do
delete_objects "${BUCKET}"
done
echo "Finished deleting objects from all specified buckets."