根据“CreatedTimestamp”删除sqs队列

发布于 2025-01-11 14:48:35 字数 662 浏览 0 评论 0原文

类似于问题 使用 boto3 批量删除 sqs 队列,我现在想删除队列基于“CreatedTimestamp”。如果创建时间(以纪元时间为单位)早于特定纪元时间戳,则应将其删除。

我尝试写一些类似于之前帖子中给出的答案的内容,但我不确定是否需要再次循环来检查创建时间。


client = boto3.client('sqs')

timestamp = '1645747200'


def delete_sqs_queues (event, context):
    response = client.list_queues()
    
    for sqs_url in response['QueueUrls']:
        get_att = client.get_queue_attributes(
            QueueUrl=sqs_url,
            AttributeNames=['CreatedTimestamp']
            )

我可以直接将 CreatedTimestamp 与变量进行比较,还是需要另一个 for 循环来迭代 CreatedTimestamp?

Similar to question Bulk delete sqs queues using boto3, I now want to delete queues based on 'CreatedTimestamp'. If the created time (in epoch time) is before a specific epoch timestamp, it should be deleted.

I tried to write something similar to answer given in the earlier post but I am not sure if I need to to loop again to check the created time.


client = boto3.client('sqs')

timestamp = '1645747200'


def delete_sqs_queues (event, context):
    response = client.list_queues()
    
    for sqs_url in response['QueueUrls']:
        get_att = client.get_queue_attributes(
            QueueUrl=sqs_url,
            AttributeNames=['CreatedTimestamp']
            )

Can I directly compare the CreatedTimestamp with a variable or do I need another for loop to iterate over the CreatedTimestamps?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

终难遇 2025-01-18 14:48:35

每个队列只有一个 CreatedTimestamp,因此您不必再次迭代:

    for sqs_url in response['QueueUrls']:
        get_att = client.get_queue_attributes(
            QueueUrl=sqs_url,
            AttributeNames=['CreatedTimestamp']
            )
        
        queue_timestamp = get_att['Attributes']['CreatedTimestamp']
        print(queue_timestamp)

        # for example
        if queue_timestamp < timestamp:
            print(f'Delete {sqs_url} because of {queue_timestamp}')   

There is only one CreatedTimestamp for each queue, thus you don't have to iterate again:

    for sqs_url in response['QueueUrls']:
        get_att = client.get_queue_attributes(
            QueueUrl=sqs_url,
            AttributeNames=['CreatedTimestamp']
            )
        
        queue_timestamp = get_att['Attributes']['CreatedTimestamp']
        print(queue_timestamp)

        # for example
        if queue_timestamp < timestamp:
            print(f'Delete {sqs_url} because of {queue_timestamp}')   

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文