Gabriel Schenker

Gabriel Schenker

ARCHIVE · LOSTECHIES · 26 SEP 2016Originally published on LosTechies on 26 Sep 2016. Some details are dated.

Bulk Delete Queues in AWS

This is a post to myself. Due to a faulty application we have a lot of dead queues in AWS SQS. To get rid of them I wrote the following script that I executed in a container that has the AWS CLI installed

prefix="[your-prefix-here]"
queues=$(aws sqs list-queues --queue-name-prefix $prefix)
for q in ${queues[@]}
do
  if [ "${q:0:1}" == "\"" ]; then
          x=${q:1:${#q}-3}
          if [ $x != "QueueUrls" ]; then
                  aws sqs delete-queue --queue-url $x
          fi
  fi
done

The script is quick and dirty and deals with the fact that the AWS CLI returns the list of queues as a JSON array.