Looking for an easy way to bulk delete SQS queues and SNS topics

0

When we started out with Rekognition we had a ton of SQS queues as well as SNS topics created automatically. I'm looking for the best and or easiest way to bulk delete these resources. Hoping someone here has an answer or at least some insight.

nbates
已提問 2 年前檢視次數 836 次
1 個回答
1

Make a python scripts.

First do a list_.... (inlcuding paging) collecting all the arns or names of the resources).

Then make a loop to delete them one by one.

For queues:

queues = []
token = None
while True:
  if token == None:
    response = client.list_queues()
  else
    response = client.list_queues(
        NextToken=token
     )
  token = response['NextToken']
  queues.extend(response['QueueUrls'])
  if token == None:
    break
for queue in queues:
  response = client.delete_queue(
      QueueUrl=queue
  )
profile picture
JaccoPK
已回答 2 年前
  • Has this worked for you in the past? I have tried this before and didn't have any luck.

  • Scripting has worked for me in many cases. Not specifically queues or topics. Usually you would setup the topic/queues using CloudFormation/terraform/cdk (IaC) and the tool would take care of properly (batch)destroying. I added the code for queues (including paging which you might have forgotten in your previous attempt).

  • Question though: you see using Rekognition these queues and topics got auto created? You mean by using the Rekognition console?

  • Hi JaccoPK, I tried the script but facing an error while reading the NextToken in a loop. I'm getting following error, token = response.NextToken ^^^^^^^^^^^^^^^^^^ AttributeError: 'sqs.queuesCollection' object has no attribute 'NextToken'

您尚未登入。 登入 去張貼答案。

一個好的回答可以清楚地回答問題並提供建設性的意見回饋,同時有助於提問者的專業成長。

回答問題指南