How nachiket-kumar/aws-cost-optimization works
Project type and purpose
• This is a cloud-native DevSecOps + FinOps tool built on AWS.
• Its primary purpose is to automatically monitor and analyze AWS costs, emit metrics and alerts, provide recommendations, and surface cost-dashboards in Grafana/Power BI.
File structure
• src/cost_reporter/ contains Python modules that implement the core logic:
• main.py — AWS Lambda handler
• metrics_calculator.py — processes cost data into CloudWatch metrics
• cloudwatch_alerter.py — creates CloudWatch alarms for cost spikes
• slack_notifier.py — pushes alerts to Slack
• benchmark_comparator.py, recommendations.py — compare against benchmarks and generate FinOps recommendations
• src/scripts/ holds bootstrap scripts for local/demo setups.
• terraform/ defines all AWS infrastructure (Lambda, IAM roles, Inspector, GuardDuty, CloudWatch, EventBridge, S3 backend for Terraform state, etc.).
• dashboards/ holds exported Grafana JSON and Power BI .pbix.
• .github/workflows/deploy.yml orchestrates CI/CD (runs tests, lints, applies Terraform, deploys Lambda).
Readme insights
• Key technologies: AWS Lambda (runtime), Terraform (IaC), CloudWatch, Slack, Grafana & Power BI, GitHub Actions, AWS Inspector + GuardDuty + Trivy for security.
Main components & relationships
a. Components
1. GitHub Actions CI/CD pipeline
2. Terraform (IaC)
3. AWS Lambda function
4. AWS EventBridge (cron trigger)
5. AWS CloudWatch (metrics + alarms)
6. Slack (alerts via webhook)
7. Grafana & Power BI dashboards (read-only visualization)
8. AWS security services: Inspector & GuardDuty (provisioned by Terraform)
9. S3 (remote state backend)
b. Interactions
• CI/CD triggers on git push → Terraform apply → deploy Lambda & supporting resources.
• EventBridge schedules Lambda runs (e.g., daily).
• Lambda retrieves cost CSV/JSON (from AWS Cost Explorer API or embedded data), calculates metrics, publishes to CloudWatch .
• Based on threshold logic, Lambda also creates/alters CloudWatch alarms.
• On alarm breach, another Lambda or same function triggers slack_notifier to send real-time Slack messages.
• Benchmarks & recommendations modules run inside Lambda and write to S3 or push into dashboards.
• Grafana connects to CloudWatch as a data source; Power BI imports cost reports from S3 or direct CSV.
• Terraform provisions AWS Inspector and GuardDuty for DevSecOps scanning.
c. Architectural patterns
• Serverless micro-service: single-purpose AWS Lambda.
• Event-driven: EventBridge → Lambda → CloudWatch → Slack.
• Infrastructure as Code with reusable Terraform modules.
• Modular code structure separating concerns: metrics, alerts, notifications, recommendations.
d. Key technologies
• AWS Lambda, EventBridge, CloudWatch, S3, IAM
• Terraform (main.tf, variables.tf, outputs.tf, backend.tf, security.tf)
• Python 3.x modules
• Slack Webhook API
• Grafana (JSON) and Power BI (.pbix)
Detail & fidelity
• every Terraform-provisioned AWS service.
• Security scanning steps in the CI/CD flow (Trivy scan, Inspector findings).