简体   繁体   中英

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. we have 5000+ log groups in AWS Account. is there a way to list the log groups through aws cli or any script?

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. If a log group was created in any period between today and t-6 months, the log group name will be printed.

Doc to used boto3 function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM