使用boto3批量删除sqs队列

Bulk delete sqs queues using boto3

我想删除大约 300-400 sqs 队列。我正在尝试使用 lambda 函数和 boto3 来做到这一点。我的编程技能不是很好。我正在尝试做这样的事情

def delete_queues (event, context):
    response = client.list_queues(
        QueueNamePrefix='aaa-bbb-ccc'
    )

    
    for i in response:
        del_queue = client.delete_queue(QueueUrl=response[i])

列出队列会给我一个由“,”分隔的 URL 列表。

Response
{
  "QueueUrls": [
    "https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo",
    "https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo",
    "https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo",
    "https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo",
    "https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo",
    "https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo",
    "https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo",
    "https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo",
    "https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo",
    "https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo"]

我想遍历列表并删除 URL,因为删除 API 调用只需要字符串作为输入。当我 运行 这给了我以下错误:

"errorMessage": "Parameter validation failed:\nInvalid type for parameter QueueUrl, value: ['https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo', 'https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo', 'https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo', 'https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo', 'https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo', 'https://ap-southeast-2.queue.amazonaws.com/xxxx/aaa-bbb-ccc.fifo'], type: <class 'list'>, valid types: <class 'str'>"

有人可以帮我更正这个问题吗?谢谢

您可以直接遍历队列 url,而不是它们的索引。因此它应该是:

for sqs_url in response['QueueUrls']:
   print(f'Deleting {sqs_url}...')
   del_queue = client.delete_queue(QueueUrl=sqs_url)