Skip to content

ACC-Automation/aws-utilization-report

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

AWS Utilization Report

License: MIT AWS Python

Automated AWS infrastructure utilization reporting for EC2, RDS, and ECS services with customizable thresholds, multi-channel notifications, and enterprise-grade deployment options.

Architecture Overview


πŸ“‹ Table of Contents


✨ Features

Feature Description
Multi-Service Support Monitor EC2, RDS, and ECS resources in a single report
Disk Metrics (Linux & Windows) Comprehensive disk usage with GB and percentage values
Customizable Thresholds Configure warning (50%) and critical (70%) levels
Flexible Scheduling Daily, weekly, or monthly report generation
Multiple Notification Channels Email (SES/SMTP) and SNS support
Enterprise Deployment Lambda, ECS/Fargate, or Docker container options
Infrastructure as Code Terraform and CloudFormation templates included
CI/CD Ready GitHub Actions workflows for automated deployment

πŸ— Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                         AWS Utilization Report                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                                         β”‚
β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”           β”‚
β”‚   β”‚  CloudWatch  β”‚     β”‚  CloudWatch  β”‚     β”‚  CloudWatch  β”‚           β”‚
β”‚   β”‚   EC2 Metricsβ”‚     β”‚  RDS Metrics β”‚     β”‚  ECS Metrics β”‚           β”‚
β”‚   β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜           β”‚
β”‚          β”‚                    β”‚                    β”‚                    β”‚
β”‚          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                    β”‚
β”‚                               β–Ό                                         β”‚
β”‚                    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                 β”‚
β”‚                    β”‚  Lambda / ECS /  β”‚                                 β”‚
β”‚                    β”‚     Docker       β”‚                                 β”‚
β”‚                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                 β”‚
β”‚                             β”‚                                           β”‚
β”‚              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                            β”‚
β”‚              β–Ό              β–Ό              β–Ό                            β”‚
β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                  β”‚
β”‚     β”‚     S3      β”‚  β”‚  SES/SMTP   β”‚  β”‚     SNS     β”‚                  β”‚
β”‚     β”‚   Report    β”‚  β”‚    Email    β”‚  β”‚    Topic    β”‚                  β”‚
β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                  β”‚
β”‚                                                                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • AWS Account with appropriate permissions
  • Python 3.9+
  • AWS CLI configured
  • (Optional) Terraform or AWS SAM CLI for IaC deployment

Local Testing

# Clone the repository
git clone https://github.com/p05-cloud/aws-utilization-report.git
cd aws-utilization-report

# Install dependencies
pip install -r requirements.txt

# Copy and configure settings
cp config/config.example.yaml config/config.yaml
# Edit config/config.yaml with your settings

# Run locally
python scripts/run_local.py

Lambda Deployment (Quick)

# Using AWS SAM
cd infrastructure/cloudformation
sam build
sam deploy --guided

# Or using Terraform
cd infrastructure/terraform
terraform init
terraform plan
terraform apply

βš™οΈ Configuration

All settings are managed via config/config.yaml:

# Report Settings
report:
  name: "AWS Utilization Report"
  frequency: "weekly"          # daily, weekly, monthly
  services:
    ec2: true
    rds: true
    ecs: true

# Threshold Settings (percentage)
thresholds:
  warning: 50                  # Orange highlight
  critical: 70                 # Red highlight

# AWS Settings
aws:
  region: "us-east-1"
  s3_bucket: "my-reports-bucket"
  s3_prefix: "utilization-reports/"

# Notification Settings
notifications:
  email:
    enabled: true
    smtp_host: "email-smtp.us-east-1.amazonaws.com"
    smtp_port: 587
    sender: "reports@example.com"
    recipients:
      - "team@example.com"
    # For SES, store credentials in AWS Secrets Manager
    secrets_manager_key: "utilization-report-smtp"
  
  sns:
    enabled: false
    topic_arn: "arn:aws:sns:us-east-1:123456789012:utilization-alerts"

Environment Variables

For Lambda/Container deployments, you can override config with environment variables:

Variable Description Default
CONFIG_PATH Path to config file config/config.yaml
AWS_REGION AWS region us-east-1
S3_BUCKET S3 bucket for reports Required
REPORT_FREQUENCY daily/weekly/monthly weekly
THRESHOLD_WARNING Warning threshold % 50
THRESHOLD_CRITICAL Critical threshold % 70
ENABLE_EMAIL Enable email notifications true
ENABLE_SNS Enable SNS notifications false
SNS_TOPIC_ARN SNS topic ARN -

πŸ“¦ Deployment Options

Option 1: AWS Lambda (Recommended)

Using Terraform:

cd infrastructure/terraform
terraform init
terraform apply -var="s3_bucket=my-bucket" -var="email_recipients=[\"team@example.com\"]"

Using CloudFormation:

cd infrastructure/cloudformation
aws cloudformation deploy \
  --template-file template.yaml \
  --stack-name utilization-report \
  --parameter-overrides S3Bucket=my-bucket \
  --capabilities CAPABILITY_IAM

Option 2: Docker Container

# Build the image
docker build -t aws-utilization-report:latest ./docker

# Run locally
docker run -v ~/.aws:/root/.aws \
  -e S3_BUCKET=my-bucket \
  -e AWS_REGION=us-east-1 \
  aws-utilization-report:latest

# Push to ECR
aws ecr get-login-password | docker login --username AWS --password-stdin <account>.dkr.ecr.<region>.amazonaws.com
docker tag aws-utilization-report:latest <account>.dkr.ecr.<region>.amazonaws.com/aws-utilization-report:latest
docker push <account>.dkr.ecr.<region>.amazonaws.com/aws-utilization-report:latest

Option 3: ECS/Fargate

See docs/ecs-deployment.md for detailed ECS/Fargate deployment instructions.


πŸ“Š Report Sample

The generated Excel report includes three sheets:

EC2 Sheet

Application Name Instance ID Private IP State CPU Avg (%) Memory Avg (%) Volume ID Disk Size (GB) Disk Used (GB) Disk Used (%) Disk Free (GB) Disk Free (%)
Web Server i-0abc123 10.0.1.10 running 45.2 62.1 vol-xyz 100 65.5 65.5 34.5 34.5

RDS Sheet

DB Identifier Endpoint Allocated Storage (GB) CPU Avg (%) Free Memory (GB) Storage Used (GB) Storage Free (GB)
prod-db prod-db.xxx.rds.amazonaws.com 500 32.1 8.5 320.0 180.0

ECS Sheet

Service Name CPU Max (%) Memory Utilization (%) Min Tasks Max Tasks Running Tasks
api-service 78.5 65.2 2 10 4

Color Coding:

  • 🟠 Orange: Warning threshold (default: β‰₯50%)
  • πŸ”΄ Red: Critical threshold (default: β‰₯70%)

πŸ”§ IAM Permissions Required

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "ec2:DescribeInstances",
        "ec2:DescribeVolumes",
        "rds:DescribeDBInstances",
        "ecs:ListClusters",
        "ecs:ListServices",
        "ecs:DescribeServices",
        "cloudwatch:GetMetricStatistics",
        "cloudwatch:ListMetrics",
        "application-autoscaling:DescribeScalableTargets",
        "s3:PutObject",
        "s3:GetObject",
        "secretsmanager:GetSecretValue",
        "ses:SendRawEmail",
        "sns:Publish"
      ],
      "Resource": "*"
    }
  ]
}

πŸ§ͺ Testing

# Install dev dependencies
pip install -r requirements-dev.txt

# Run tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=src --cov-report=html

πŸ“ Project Structure

aws-utilization-report/
β”œβ”€β”€ README.md                    # This file
β”œβ”€β”€ LICENSE                      # MIT License
β”œβ”€β”€ CONTRIBUTING.md              # Contribution guidelines
β”œβ”€β”€ CHANGELOG.md                 # Version history
β”œβ”€β”€ requirements.txt             # Python dependencies
β”œβ”€β”€ requirements-dev.txt         # Dev dependencies
β”œβ”€β”€ .gitignore                   # Git ignore rules
β”‚
β”œβ”€β”€ src/                         # Source code
β”‚   β”œβ”€β”€ lambda_function.py       # Main Lambda handler
β”‚   β”œβ”€β”€ metrics/                 # Metric collection modules
β”‚   β”œβ”€β”€ notifications/           # Notification handlers
β”‚   └── utils/                   # Utility functions
β”‚
β”œβ”€β”€ config/                      # Configuration
β”‚   └── config.example.yaml      # Example configuration
β”‚
β”œβ”€β”€ scripts/                     # Utility scripts
β”‚   └── run_local.py             # Local execution script
β”‚
β”œβ”€β”€ docker/                      # Docker files
β”‚   β”œβ”€β”€ Dockerfile               # Container definition
β”‚   └── docker-compose.yaml      # Local Docker setup
β”‚
β”œβ”€β”€ infrastructure/              # IaC templates
β”‚   β”œβ”€β”€ terraform/               # Terraform modules
β”‚   └── cloudformation/          # SAM/CloudFormation
β”‚
β”œβ”€β”€ tests/                       # Test suite
β”‚   └── test_metrics.py          # Unit tests
β”‚
β”œβ”€β”€ docs/                        # Documentation
β”‚   β”œβ”€β”€ architecture.md          # Architecture details
β”‚   β”œβ”€β”€ setup-guide.md           # Detailed setup guide
β”‚   └── images/                  # Documentation images
β”‚
└── .github/                     # GitHub specific
    └── workflows/               # CI/CD pipelines
        β”œβ”€β”€ ci.yml               # Continuous Integration
        └── deploy.yml           # Deployment workflow

🀝 Contributing

Contributions are welcome! Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.


πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘€ Author

p05-cloud


⭐ Show Your Support

Give a ⭐️ if this project helped you!


πŸ“ Changelog

See CHANGELOG.md for version history.

About

No description, website, or topics provided.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 80.8%
  • HCL 17.5%
  • Dockerfile 1.7%