A Python script to analyze AWS CloudWatch log groups, showing their size, retention period, and other metrics in a formatted table.
- List all CloudWatch log groups in a specified AWS region
- Display log group size in human-readable format (B, KB, MB, GB, TB)
- Show retention period for each log group
- Filter log groups using regex patterns
- Configurable limit (default: 50 log groups)
- Formatted table output with summary statistics
- Python 3.6+
- AWS CLI configured or AWS credentials available
- Required Python packages (see requirements.txt)
- Clone or download this repository
- Install required dependencies:
pip install -r requirements.txt
Ensure your AWS credentials are configured. You can use any of these methods:
-
AWS Profile (recommended):
export AWS_PROFILE=your-profile-name
-
Environment Variables:
export AWS_ACCESS_KEY_ID=your-access-key export AWS_SECRET_ACCESS_KEY=your-secret-key
-
AWS CLI Default Profile:
aws configure
python aws-log-summary.py --region us-east-1
python aws-log-summary.py --region us-east-1 --filter "abcd*"
python aws-log-summary.py --region us-east-1 --limit 100
export AWS_PROFILE=foobar
python aws-log-summary.py --region us-east-1 --filter "production-*" --limit 25
--region
(required): AWS region to analyze--filter
(optional): Regex pattern to filter log group names--limit
(optional): Maximum number of log groups to analyze (default: 50)
Analyzing CloudWatch logs in region: us-east-1
Limit: 50 log groups
+------------------+--------+------------+
| Log Group | Size | Retention |
+==================+========+============+
| aaa-bbb | 2.1MB | 7 days |
| production-api | 15.3GB | 30 days |
| staging-web | 456.2KB| Never expire|
+------------------+--------+------------+
Summary:
Total log groups: 3
Total size: 15.3GB
Your AWS user/role needs the following permissions:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:DescribeLogGroups"
],
"Resource": "*"
}
]
}
The script includes error handling for:
- AWS authentication issues
- Network connectivity problems
- Invalid regions
- Permission denied errors
boto3
: AWS SDK for Pythontabulate
: Pretty-print tabular data
This project is provided as-is for educational and operational purposes.