【问题标题】:How to list all the log group in Cloudwatch using boto3如何使用 boto3 列出 Cloudwatch 中的所有日志组
【发布时间】:2022-02-09 21:55:50
【问题描述】:

如何使用 Boto3 列出 Cloudwatch 中的所有日志组。当我尝试以下语法时。我得到错误。

client = boto3.client('logs')

response = client.describe_log_groups(limit=51)

检测到验证错误:“limit”处的值“51”未能满足 约束:成员的值必须小于或等于 50

基于documentation,我们可以超过 50

limit (integer) -- 返回的最大项目数。如果你不 指定一个值,默认最多 50 项。

【问题讨论】:

    标签: python amazon-web-services boto3


    【解决方案1】:

    如有疑问,请始终联系API documentation,上面写着以下内容:

    有效范围:最小值为 1。最大值为 50。

    要解决您的问题,您需要使用paginator

    paginator = logs_client.get_paginator('describe_log_groups')
    for page in paginator.paginate():
        for group in page['logGroups']:
            print(group)
    

    【讨论】:

      猜你喜欢
      • 2020-08-12
      • 1970-01-01
      • 2020-04-02
      • 1970-01-01
      • 2020-04-25
      • 1970-01-01
      • 2022-08-04
      • 2017-10-10
      • 2022-11-25
      相关资源
      最近更新 更多