skip to Main Content

I have many topics and queues named in the same pattern. Now I need to delete them all in bulk using some pattern with a wildcard. The AWS CLI only allows deleting one by one. Same in the AWS Console – the list of queues and topics have radio boxes in their rows allowing to delete one by one only. How to delete multiple items at once by a pattern? What script can I use for that?

2

Answers


  1. Using the CLI in your shell or CloudShell you can do something like:

    topics=$(aws sns list-topics --query 'Topics[*]' --output text | grep <YOUR_PATTERN>)
    for topic in $topics 
    do 
      echo "Deleting topic" $topic
      aws sns delete-topic --topic-arn $topic
    done
    

    Do the same with the CLI commands for sqs.

    Login or Signup to reply.
  2. you can create script for your task and you can use cli in script for bulk deletion

    To Delete SNS Topics by Pattern:

    #!/bin/bash
    aws sns list-topics --query 'Topics[].TopicArn' --output text | grep "<your-pattern>" | while read -r topic_arn
    do
        echo "Deleting SNS topic: $topic_arn"
        aws sns delete-topic --topic-arn "$topic_arn"
    done
    

    To Delete SQS Queues by Pattern:

    #!/bin/bash
    aws sqs list-queues --query 'QueueUrls[]' --output text | grep "your-pattern" | while read -r queue_url
    do
        echo "Deleting SQS queue: $queue_url"
        aws sqs delete-queue --queue-url "$queue_url"
    done
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search