Skip to content

Instantly share code, notes, and snippets.

@zxkane
Last active January 13, 2022 14:46
Show Gist options
  • Save zxkane/65b9dc41e6fcd10900334f653f6f7beb to your computer and use it in GitHub Desktop.
Save zxkane/65b9dc41e6fcd10900334f653f6f7beb to your computer and use it in GitHub Desktop.
purge obsolete resources after deleting nexus3 stack created by solution https://github.com/aws-samples/nexus-oss-on-aws
local-empty-dir/
#!/bin/bash -xe
for filesystem in $(aws efs describe-file-systems --query "FileSystems[?Tags[?Value=='nexus3']].FileSystemId" --output json | jq '.[]' | jq -r '.'); do
aws efs delete-file-system --file-system-id $filesystem
echo "purged efs filesystem $filesystem"
done
purge_buckets () {
local name=$1
for bucket in $(aws s3api list-buckets --query "Buckets[?starts_with(Name,\`$name\`)==\`true\`].Name"|jq -r '.[]'); do
region=$(aws s3api get-bucket-location --bucket $bucket --output text)
withregion=""
if [ "$region" != "None" ]
then
withregion="--region $region"
fi
mkdir -p local-empty-dir
aws s3 sync --delete local-empty-dir s3://$bucket/ $withregion
aws s3 rb s3://$bucket --force $withregion
echo "purged s3 bucket $bucket"
done
}
BUCEKT_NAME=$1
if [ -z "$BUCEKT_NAME" ]
then
echo "pls specify BUCKET_NAME as bucket prefix."
exit 9
fi
echo Bucket name is "$BUCEKT_NAME"
purge_buckets "$BUCEKT_NAME"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment