Skip to content

nickcube2/AI-Cost-Optimization-Dashboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

πŸ€– AI Cost Optimization Dashboard

AI-powered AWS cost analysis that identified $15,400/month in optimization opportunities across EC2, RDS, and S3 β€” fully automated, Slack-delivered, production-ready.

Python AWS Claude AI OpenAI Terraform Docker License


πŸ’‘ Why This Exists

Cloud teams waste thousands on idle resources every month β€” not because they don't care, but because manual cost review doesn't scale. This tool automates the entire FinOps loop: fetch β†’ analyze β†’ recommend β†’ alert β†’ track.

Built by a DevOps engineer who's operated 24/7 broadcast infrastructure where every dollar of cloud spend is visible and accountable.


πŸ“Š Real-World Impact

Metric Result
πŸ’° Monthly savings identified $15,400/month
☁️ Services analyzed EC2, RDS, S3, Lambda, NAT Gateway, KMS
⚑ Time to first recommendation < 2 minutes
πŸ“¬ Delivery Automated Slack weekly reports
πŸ—οΈ Deployment Docker + Terraform on AWS

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   AWS Account   │────▢│   Python Engine      │────▢│   LLM Provider   β”‚
β”‚  Cost Explorer  β”‚     β”‚  - Cost fetching     β”‚     β”‚  Claude / OpenAI β”‚
β”‚  (CUR / API)    β”‚     β”‚  - Anomaly detection β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚  - Forecasting       β”‚              β”‚
                        β”‚  - ROI ranking       β”‚              β–Ό
                        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                                   β”‚                  β”‚  Recommendations β”‚
                          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚  + Action Items  β”‚
                          β”‚                 β”‚         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
                    β”‚ Flask Web  β”‚  β”‚ Slack Webhookβ”‚
                    β”‚ Dashboard  β”‚  β”‚  (Weekly)    β”‚
                    β”‚ Chart.js   β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

For regulated environments (banking / fintech):

CUR β†’ S3 β†’ Athena (auditable SQL) β†’ EventBridge β†’ Lambda β†’ Dashboard

Fully governed, deterministic, KMS-encrypted, IAM-scoped.


✨ Features

Feature Description
πŸ” Cost Analysis 7/30/90-day spend breakdown by service, account, tag
πŸ€– AI Recommendations Claude or OpenAI ranks opportunities by ROI
🚨 Anomaly Detection Z-score + IQR detects spend spikes before they escalate
πŸ“ˆ Forecasting 30-day cost projections with confidence intervals
πŸ’Ύ Savings Tracker Tracks implemented optimizations and ROI over time
πŸ”§ Auto-Remediation Generates Terraform stubs for approved changes
πŸ“Š Web Dashboard Flask + Chart.js with SSE real-time updates
πŸ“„ PDF Export Print-ready reports from the dashboard
πŸ“¬ Slack Integration Weekly automated delivery with action items
🐳 Docker + Compose One-command local or cloud deployment
☁️ Terraform Production AWS deployment via IaC
πŸ”’ Security Token auth, DRY_RUN mode, IAM least-privilege

πŸš€ Quick Start

Prerequisites

  • Python 3.11 or 3.12 (not 3.14)
  • AWS account with Cost Explorer enabled
  • OpenAI or Claude API key
  • Slack webhook (optional)

1. Clone & Install

git clone https://github.com/nickcube2/AI-Cost-Optimization-Dashboard.git
cd AI-Cost-Optimization-Dashboard
pip install -r requirements.txt

2. Configure

cp .env.example .env
# .env
AWS_REGION=us-east-1
LLM_PROVIDER=anthropic          # anthropic | openai | mock
CLAUDE_API_KEY=sk-ant-...
OPENAI_API_KEY=sk-...
SLACK_WEBHOOK_URL=https://hooks.slack.com/...
MONTHLY_BUDGET=5000
DAYS_TO_ANALYZE=30
DRY_RUN=false

3. Run

CLI (quickest)

python cost_optimizer.py

Web Dashboard (local)

python app.py
# Open http://localhost:5000

Demo mode (no AWS creds needed)

python advanced_optimizer.py --demo

Docker

docker compose up --build
# Open http://localhost:5000

🐳 Docker Deployment

# Dashboard
docker run --rm -p 5000:5000 --env-file .env \
  -e DASHBOARD_HOST=0.0.0.0 \
  ai-cost-optimization-dashboard

# CLI workflow
docker run --rm --env-file .env \
  ai-cost-optimization-dashboard python advanced_optimizer.py --demo

☁️ Terraform Deployment (AWS)

cd terraform
cp terraform.tfvars.example terraform.tfvars
terraform init && terraform plan && terraform apply
# Makefile shortcuts
make tf-plan
make tf-apply
make tf-destroy

πŸ”§ Advanced Usage

# With AI-powered 30-day forecast
python advanced_optimizer.py --report --ai-forecast

# Auto-remediation plan + Terraform stubs (dry-run safe)
python advanced_optimizer.py --auto-remediate --generate-terraform

# Full report output
python advanced_optimizer.py --report

πŸ“‹ Sample Output

══════════════════════════════════════════════════════════════════════
πŸš€ AI COST OPTIMIZATION DASHBOARD
══════════════════════════════════════════════════════════════════════

πŸ“Š Fetching AWS cost data for last 30 days...
   πŸ“… Date range: 2026-01-17 to 2026-02-16
   πŸ“ˆ Trend: up 8.4% vs previous 30 days
   βœ… Total: $12,858.00 | Services: 12

πŸ’° Cost Distribution:
──────────────────────────────────────────────────────────────────────
EC2                  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ  $  4,892.00
RDS                  β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ        $  3,241.00
S3                   β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ              $  2,180.00
Lambda               β–ˆβ–ˆβ–ˆβ–ˆ                  $    890.00
NAT Gateway          β–ˆβ–ˆ                    $    520.00
──────────────────────────────────────────────────────────────────────

πŸ€– AI RECOMMENDATIONS

## πŸ“Š SPENDING OVERVIEW
Total: $12,858 | Trend: +8.4% | Budget: On Track

## πŸ’° TOP OPPORTUNITIES
1. EC2 Right-sizing (prod cluster)       β†’ Save $4,200/mo  [Quick Win]
2. RDS Reserved Instance conversion      β†’ Save $1,800/mo  [Medium]
3. S3 Intelligent-Tiering (archive)      β†’ Save $950/mo    [Quick Win]
4. NAT Gateway consolidation             β†’ Save $380/mo    [Medium]

ROI Total: $7,330/month β†’ $87,960/year

πŸ”’ AWS IAM Policy (Least Privilege)

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Action": [
      "ce:GetCostAndUsage",
      "ce:GetCostForecast",
      "ce:GetDimensionValues",
      "ce:GetReservationUtilization"
    ],
    "Resource": "*"
  }]
}

πŸ” Security Features

  • DASHBOARD_API_TOKEN β€” token-based auth for all /api/* endpoints
  • DRY_RUN=true β€” full execution without any API charges
  • DASHBOARD_CACHE_TTL β€” prevents repeated AWS API calls
  • IAM scoped to read-only Cost Explorer permissions
  • VPC endpoint support for regulated environments

πŸ“ Project Structure

ai-cost-optimization-dashboard/
β”œβ”€β”€ app.py                    # Flask web dashboard (SSE + Chart.js)
β”œβ”€β”€ cost_optimizer.py         # Core optimizer (CLI entry point)
β”œβ”€β”€ advanced_optimizer.py     # Multi-feature demo runner
β”œβ”€β”€ anomaly_detector.py       # Z-score + IQR anomaly detection
β”œβ”€β”€ cost_forecaster.py        # 30-day cost forecasting
β”œβ”€β”€ auto_remediator.py        # Terraform auto-remediation stubs
β”œβ”€β”€ savings_tracker.py        # ROI tracking over time
β”œβ”€β”€ llm_client.py             # Cloud-agnostic LLM client (Claude/OpenAI)
β”œβ”€β”€ dashboard_data.py         # Dashboard JSON payload builder
β”œβ”€β”€ Dockerfile                # Container definition
β”œβ”€β”€ docker-compose.yml        # Local orchestration
β”œβ”€β”€ Makefile                  # Convenience commands
β”œβ”€β”€ terraform/                # AWS infrastructure as code
β”œβ”€β”€ static/                   # Frontend assets
β”œβ”€β”€ templates/                # Flask HTML templates
β”œβ”€β”€ screenshots/              # Dashboard preview images
└── reports/                  # Generated cost reports

πŸ—ΊοΈ Roadmap

  • Core cost analysis + AI recommendations (Week 1)
  • Slack integration + cron scheduling (Week 1)
  • Anomaly detection + trend analysis (Week 1)
  • ROI-based ranking + risk assessment (Week 1)
  • Multi-account support + savings tracker (Week 2)
  • Web dashboard β€” Flask + Chart.js + SSE (Week 3)
  • Terraform auto-remediation stubs (Week 4)
  • Docker + Terraform production deployment (Week 4)
  • Multi-cloud support (Azure Cost Management, GCP Billing)
  • Slack slash command (/aws-costs) for on-demand reports
  • Grafana dashboard integration
  • GitHub Actions scheduled workflow

πŸ‘€ Author

Nicholas Awuni β€” Senior DevOps / Cloud Engineer
AWS Certified Solutions Architect | HashiCorp Terraform Associate | FinOps Practitioner

LinkedIn GitHub

"I've seen teams waste thousands on idle resources β€” not from negligence, but because manual cost review doesn't scale. This project makes FinOps automatic and actionable."


πŸ“„ License

MIT β€” see LICENSE

About

AI-powered AWS cost optimization dashboard using Claude AI. Analyzes spending patterns, identifies savings opportunities, and delivers weekly recommendations via Slack. Identified $15,400/month in optimizations across EC2, RDS, and S3. Built with Python + AWS Cost Explorer + Anthropic Claude.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors