Skip to content

Instantly share code, notes, and snippets.

@NeilMasters
Created December 12, 2023 20:12
Show Gist options
  • Save NeilMasters/e13245f0408be5d609356775f14553bf to your computer and use it in GitHub Desktop.
Save NeilMasters/e13245f0408be5d609356775f14553bf to your computer and use it in GitHub Desktop.
Delete AWS queues using a prefix and optional dry-run
#!/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