[英]Is there a way to list the CloudWatch log groups which are created 6 months ago
I wanted to list the CloudWatch log groups which are created 6 months back.我想列出 6 个月前创建的 CloudWatch 日志组。 we have 5000+ log groups in AWS Account.我们在 AWS 账户中有 5000 多个日志组。 is there a way to list the log groups through aws cli or any script?有没有办法通过 aws cli 或任何脚本列出日志组?
import boto3
import datetime
t_minus_6_months = datetime.datetime.now() - datetime.timedelta(days=180)
logs_client = boto3.client('logs')
paginator = logs_client.get_paginator('describe_log_groups')
for page in paginator.paginate():
for group in page['logGroups']:
if group['creationTime'] >= t_minus_6_months:
print(group['logGroupName'])
Since you said you have more than 5000 log groups, you have to use a paginator.既然你说你有超过 5000 个日志组,你必须使用分页器。 If a log group was created in any period between today and t-6 months, the log group name will be printed.如果在今天和 t-6 个月之间的任何时间段内创建了日志组,则会打印日志组名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.