Skip to content

Instantly share code, notes, and snippets.

@NeilMasters
Created May 30, 2024 09:29
Show Gist options
  • Save NeilMasters/77b30cec6a566bb7a4b762aa01bf17ce to your computer and use it in GitHub Desktop.
Save NeilMasters/77b30cec6a566bb7a4b762aa01bf17ce to your computer and use it in GitHub Desktop.
Delete sqs queues using a prefix.
#!/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