Created
December 12, 2023 20:12
-
-
Save NeilMasters/e13245f0408be5d609356775f14553bf to your computer and use it in GitHub Desktop.
Delete AWS queues using a prefix and optional dry-run
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
#!/bin/bash | |
PREFIX=$1 | |
DRY_RUN=$2 | |
echo "Starting the purge of queues that have the prefix of ${PREFIX}" | |
# Get the list of queues with the $ PREFIX and store as a block of json | |
QUEUES=$(aws-vault exec $AWS_PROFILE -- aws sqs list-queues --queue-name-prefix=${PREFIX} | jq '.QueueUrls') | |
echo $QUEUES > /tmp/queues.json | |
jq -r '.[]' /tmp/queues.json | while read QUEUE; do | |
if [[ ${DRY_RUN} == "no" ]] | |
then | |
echo "Deleting ${QUEUE}" | |
aws-vault exec $AWS_PROFILE -- aws sqs delete-queue --queue-url "${QUEUE}" | |
else | |
echo "[DRY RUN] Deleting ${QUEUE}" | |
fi | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment