Created
May 30, 2024 09:29
-
-
Save NeilMasters/77b30cec6a566bb7a4b762aa01bf17ce to your computer and use it in GitHub Desktop.
Delete sqs queues using a prefix.
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}" | |
while true | |
do | |
# 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 --region eu-west-2 --queue-url "${QUEUE}" | |
else | |
echo "[DRY RUN] Deleting ${QUEUE}" | |
fi | |
done; | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment