Skip to content

Instantly share code, notes, and snippets.

@NeilMasters
Created May 28, 2025 11:34
Show Gist options
  • Save NeilMasters/8d5d5390246439db83e43b6d7db83e74 to your computer and use it in GitHub Desktop.
Save NeilMasters/8d5d5390246439db83e43b6d7db83e74 to your computer and use it in GitHub Desktop.
Purge SQS queues that match a provided prefix
#!/bin/bash
PREFIX=$1
DRY_RUN=$2
REGION=$3
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 sqs list-queues --region "${REGION}" --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 sqs delete-queue --region "${REGION}" --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