Skip to main content

Posts

Showing posts with the label CloudWatch

Python script to list all AWS CloudWatch logs with their retention time

The following Python script will help you to export list of any all the CloudWatch logs with their retention time and size of the log group an AWS account. The script also helps you to save the output within CSV file. #!/usr/bin/env python3.8 #This script will save the list of CloudWatch log group names, their retention time and # size (in MBs) in to CSV file import boto3 import time import csv # Setting up AWS profile and region profile = "default" region = "us-east-1" session = boto3 . Session ( profile_name = profile , region_name = region ) #getting current date and time date_time = time . strftime ( " %d %m%Y_%H%M" ) # setting up file name fname = "CloudWatch-Logs_" ftime = date_time fext = ".csv" filename = fname + ftime + fext # open file to write output with open ( filename , 'w' ) as f :     print ( 'Profile, Region,Log Group Name, Retention Time (in days), Size (in MB)' , file = f )   cw_logs =