https://github.com/codecollab-co/infra-cost
CLI tool to perform cost analysis on your infrastructure account with Slack integration.
https://github.com/codecollab-co/infra-cost
aws aws-cost aws-cost-explorer azure azure-cost gcp gcp-cost-report github-actions
Last synced: 7 months ago
JSON representation
CLI tool to perform cost analysis on your infrastructure account with Slack integration.
- Host: GitHub
- URL: https://github.com/codecollab-co/infra-cost
- Owner: codecollab-co
- License: mit
- Created: 2025-03-22T13:09:53.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-07T07:00:23.000Z (over 1 year ago)
- Last Synced: 2025-04-07T07:22:40.259Z (over 1 year ago)
- Topics: aws, aws-cost, aws-cost-explorer, azure, azure-cost, gcp, gcp-cost-report, github-actions
- Language: TypeScript
- Homepage:
- Size: 33.7 MB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ฐ infra-cost
**Multi-cloud FinOps CLI tool for comprehensive cost analysis and infrastructure optimization**
[](https://badge.fury.io/js/infra-cost)
[](https://npmjs.org/package/infra-cost)
[](https://opensource.org/licenses/MIT)
[](https://github.com/codecollab-co/infra-cost/issues)
[](https://github.com/codecollab-co/infra-cost/stargazers)
*Take control of your cloud costs across AWS, Google Cloud, Azure, Alibaba Cloud, and Oracle Cloud* ๐
[Installation](#-installation) โข [Quick Start](#-quick-start) โข [Features](#-features) โข [Documentation](#-documentation) โข [Contributing](#-contributing)
---
## ๐ฏ Why infra-cost?
**Save money. Optimize resources. Make informed decisions.**
- ๐ธ **Reduce cloud spend** by up to 30% with actionable insights
- ๐ **Multi-cloud visibility** - see costs across all your providers in one place
- โก **Real-time analysis** - get instant cost breakdowns and trends
- ๐ค **AI-powered recommendations** for optimization opportunities
- ๐ **Executive reports** - beautiful PDF reports for stakeholders
- ๐ **Smart alerting** - proactive cost anomaly detection
- ๐ฌ **Team collaboration** - Slack integration for cost awareness
## ๐ Features
### ๐ **Multi-Cloud Support**
- **AWS** โ
(Full support with Cost Explorer integration)
- **Google Cloud** ๐ง (Architecture ready, coming soon)
- **Microsoft Azure** ๐ง (Architecture ready, coming soon)
- **Alibaba Cloud** ๐ง (Architecture ready, coming soon)
- **Oracle Cloud** ๐ง (Architecture ready, coming soon)
### ๐ **Comprehensive Analytics**
- **Cost Forecasting** - AI-powered predictions for future spending
- **Budget Monitoring** - Track against budgets with smart alerts
- **Resource Rightsizing** - ML recommendations for optimal instance sizes
- **Sustainability Analysis** - Carbon footprint tracking and green recommendations
- **Security Cost Analysis** - Security posture vs. cost optimization
- **Anomaly Detection** - AI-powered cost spike identification
### ๐๏ธ **Advanced Features**
- **Interactive Dashboards** - Rich terminal UI with real-time data
- **PDF Report Generation** - Executive summaries and technical deep-dives
- **Cross-Cloud Optimization** - Find the best provider for each workload
- **Automated Optimization** - Execute cost-saving actions automatically
- **Audit Logging** - Comprehensive compliance tracking
- **Enterprise Multi-tenancy** - Team and organization management
### ๐ง **Developer Experience**
- **Multiple output formats**: Fancy tables, plain text, JSON, CSV, Excel
- **Flexible authentication**: Environment variables, IAM roles, profiles
- **CI/CD Integration**: GitHub Actions, Jenkins, GitLab CI
- **API Server**: REST endpoints for custom integrations
- **Webhook Support**: Real-time notifications and integrations
## ๐ฆ Installation
### npm (Recommended)
```bash
npm install -g infra-cost
```
### Homebrew (macOS/Linux)
```bash
brew tap codecollab-co/tap
brew install infra-cost
```
### npx (No installation required)
```bash
npx infra-cost
```
### Docker
```bash
docker run --rm codecollab-co/infra-cost --help
```
### GitHub Action
```yaml
- uses: codecollab-co/infra-cost@v0.3.0
with:
provider: aws
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
```
## ๐ฏ Quick Start
### 1. Basic AWS Cost Analysis
```bash
# Using default AWS credentials
infra-cost
# Get a 6-month cost trend with forecasting
infra-cost --trend --forecast 30
# Interactive multi-cloud dashboard
infra-cost --multi-cloud-dashboard
```
### 2. Advanced Analysis
```bash
# Generate executive PDF report
infra-cost --executive-summary --pdf-report quarterly-report.pdf
# AI-powered anomaly detection
infra-cost --anomaly-detect --anomaly-realtime
# Comprehensive sustainability analysis
infra-cost --sustainability --carbon-footprint --green-recommendations
```
### 3. Team Collaboration
```bash
# Send daily cost report to Slack
infra-cost --slack-token YOUR_TOKEN --slack-channel "#finops" --smart-alerts
# Start real-time cost monitoring
infra-cost --monitor --alert-threshold 1000 --alert-channel slack
```
## ๐ Authentication
### AWS Authentication (Multiple Methods)
#### 1. Environment Variables (Recommended)
```bash
export AWS_ACCESS_KEY_ID=your_access_key
export AWS_SECRET_ACCESS_KEY=your_secret_key
export AWS_REGION=us-east-1
infra-cost
```
#### 2. AWS Profiles
```bash
# Use default profile
infra-cost
# Use specific profile
infra-cost --profile production
# Auto-discover profiles
infra-cost --discover-profiles --auto-profile
```
#### 3. IAM Roles (EC2/Lambda/ECS)
```bash
# Automatically uses attached IAM role
infra-cost
```
#### 4. AWS SSO
```bash
aws sso login --profile my-sso-profile
infra-cost --profile my-sso-profile
```
### Multi-Cloud Setup (Coming Soon)
```bash
# Google Cloud Platform
infra-cost --provider gcp --project-id my-project --key-file service-account.json
# Microsoft Azure
infra-cost --provider azure --subscription-id sub-id --tenant-id tenant-id
# Cross-cloud comparison
infra-cost --compare-clouds aws,gcp,azure --optimization-report
```
## ๐ Output Examples
### Default Rich Terminal UI
```bash
infra-cost --smart-alerts --compact
```

### Executive Dashboard
```bash
infra-cost --executive-summary
```

### JSON for Automation
```bash
infra-cost --json --forecast 30 --analytics-insights
```
### PDF Reports
```bash
infra-cost --pdf-report monthly-report.pdf --trend --optimization-tips
```
## ๐ฌ Slack Integration
### Enhanced Team Collaboration
- **Rich cost breakdowns** with visual charts
- **Proactive alerts** for budget overruns and anomalies
- **Automated workflows** for approval processes
- **Team cost awareness** with regular updates
### Setup & Usage
```bash
# Create Slack app with chat:write permissions
# Get OAuth token and channel ID
# Send cost report
infra-cost --slack-token xoxb-your-token --slack-channel "#finops"
# Enable smart alerts
infra-cost --slack-token xoxb-your-token --slack-channel "#alerts" --smart-alerts
```
### Automated Daily Reports
```yaml
name: Daily FinOps Report
on:
schedule:
- cron: '0 9 * * 1-5' # Weekdays 9 AM UTC
jobs:
cost-report:
runs-on: ubuntu-latest
steps:
- run: |
npx infra-cost \
--executive-summary \
--slack-token ${{ secrets.SLACK_TOKEN }} \
--slack-channel ${{ secrets.SLACK_CHANNEL }} \
--smart-alerts --trends 7
```
## ๐ค GitHub Actions Integration
**infra-cost** is available as a GitHub Action on the [GitHub Marketplace](https://github.com/marketplace/actions/infra-cost-multi-cloud-finops-analysis), making it easy to integrate cost analysis into your CI/CD workflows.
### Basic Usage
```yaml
name: Cost Analysis
on: [push, pull_request]
jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: codecollab-co/infra-cost@v0.3.0
with:
provider: aws
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
analysis-type: summary
```
### PR Cost Check with Comments
```yaml
name: PR Cost Check
on:
pull_request:
branches: [main]
jobs:
cost-check:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: codecollab-co/infra-cost@v0.3.0
with:
provider: aws
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
analysis-type: delta
delta-threshold: '10'
comment-on-pr: 'true'
```
### Daily Cost Report to Slack
```yaml
name: Daily Cost Report
on:
schedule:
- cron: '0 9 * * *'
jobs:
report:
runs-on: ubuntu-latest
steps:
- uses: codecollab-co/infra-cost@v0.3.0
with:
provider: aws
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
analysis-type: finops
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
```
### Action Inputs
| Input | Description | Default |
|-------|-------------|---------|
| `provider` | Cloud provider (aws, gcp, azure, alicloud, oracle) | `aws` |
| `profile` | Cloud provider profile | `default` |
| `region` | Cloud provider region | `us-east-1` |
| `aws-access-key-id` | AWS Access Key ID | - |
| `aws-secret-access-key` | AWS Secret Access Key | - |
| `analysis-type` | Type of analysis (summary, detailed, delta, forecast, anomaly, finops, audit) | `summary` |
| `forecast-days` | Days for forecast | `30` |
| `delta-threshold` | Alert threshold for cost changes (%) | `10` |
| `output-format` | Output format (text, json) | `text` |
| `slack-webhook` | Slack webhook URL | - |
| `comment-on-pr` | Post analysis as PR comment | `false` |
| `fail-on-threshold` | Fail if costs exceed threshold | `false` |
### Action Outputs
| Output | Description |
|--------|-------------|
| `total-cost` | Total cost for the analysis period |
| `cost-change` | Cost change percentage |
| `forecast-cost` | Forecasted cost |
| `anomalies-detected` | Number of anomalies detected |
| `report-json` | Full report in JSON format |
See [example workflows](.github/workflows/examples/) for more use cases.
## ๐ง Advanced Usage
### Cost Forecasting & Analytics
```bash
# AI-powered forecasting with multiple models
infra-cost --forecast 90 --forecast-model AUTO --forecast-confidence 95
# Business intelligence insights
infra-cost --analytics --analytics-insights --analytics-drivers
# Custom dashboards
infra-cost --dashboard-create "Monthly Review" --chart-create "line:Cost Trends"
```
### Optimization & Automation
```bash
# Generate optimization recommendations
infra-cost --finops --optimization-tips --rightsize --sustainability
# Automated optimization (dry-run first!)
infra-cost --optimize-dry-run --optimize-rules resize,schedule,unused
# Cross-cloud cost comparison
infra-cost --compare-clouds aws,gcp --optimization-report
```
### Enterprise Features
```bash
# Multi-tenant management
infra-cost --enterprise --tenants --platform-metrics
# API server for integrations
infra-cost --api-server --api-port 3000 --webhook-create
# Comprehensive audit logging
infra-cost --audit --compliance-check soc2 --audit-export json
```
## ๐๏ธ Architecture & Extensibility
### Multi-Cloud Provider Pattern
```
src/
โโโ providers/
โ โโโ factory.ts # Provider factory
โ โโโ aws.ts # AWS implementation โ
โ โโโ gcp.ts # Google Cloud ๐ง
โ โโโ azure.ts # Azure ๐ง
โ โโโ alicloud.ts # Alibaba Cloud ๐ง
โ โโโ oracle.ts # Oracle Cloud ๐ง
โโโ analytics/ # AI/ML cost analysis
โโโ optimization/ # Cost optimization engines
โโโ visualization/ # Dashboards & charts
โโโ integrations/ # Third-party integrations
โโโ enterprise/ # Multi-tenant features
```
### Key Design Principles
- **Abstract provider interface** for consistent multi-cloud API
- **Plugin architecture** for easy extensibility
- **Type-safe implementation** with comprehensive TypeScript coverage
- **Modular design** allowing feature composition
- **Performance optimized** with efficient data processing
## ๐ Roadmap
### Q4 2024
- โ
Enhanced terminal UI and visualization
- โ
AI-powered anomaly detection
- โ
Comprehensive PDF reporting
- โ
Advanced Slack integration
- ๐ง Google Cloud Platform support
### Q1 2025
- ๐ฎ Microsoft Azure integration
- ๐ฎ Advanced forecasting models
- ๐ฎ Mobile app companion
- ๐ฎ Sustainability tracking expansion
### Q2 2025
- ๐ฎ Alibaba Cloud & Oracle Cloud support
- ๐ฎ Advanced automation engine
- ๐ฎ Enterprise SSO integration
- ๐ฎ Custom plugin system
## ๐ Requirements & Permissions
### AWS Permissions Required
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "InfraCostMinimalPermissions",
"Effect": "Allow",
"Action": [
"iam:ListAccountAliases",
"ce:GetCostAndUsage",
"ce:GetRightsizingRecommendation",
"ce:GetSavingsUtilization",
"budgets:ViewBudget",
"sts:GetCallerIdentity"
],
"Resource": "*"
}
]
}
```
### System Requirements
- Node.js 20+ (required)
- Memory: 512MB+ available
- Network: Internet access for cloud provider APIs
- Optional: Docker for containerized deployments
## ๐งช Development
### Local Development Setup
```bash
# Clone repository
git clone https://github.com/codecollab-co/infra-cost.git
cd infra-cost
# Install dependencies
npm install
# Build project
npm run build
# Run tests
npm test
# Start development server
npm run dev
```
### Testing & Quality Assurance
```bash
# Type checking
npm run typecheck
# Linting
npm run lint
# Security audit
npm audit
# Test coverage
npm run test:coverage
```
### Release Management
```bash
# Check current version status
npm run version:check
# Bump version
npm run version:bump:patch # Bug fixes
npm run version:bump:minor # New features
npm run version:bump:major # Breaking changes
# Prepare release
npm run prepare-release
```
## ๐ค Contributing
We welcome contributions from the community! Here's how you can help:
### ๐ Ways to Contribute
- **โญ Star this repository** to show your support
- **๐ Report bugs** and suggest improvements via [issues](https://github.com/codecollab-co/infra-cost/issues)
- **๐ Improve documentation** - help others understand and use the tool
- **๐ง Add cloud provider support** - help us expand to more providers
- **๐งช Write tests** - improve code quality and reliability
- **๐ก Suggest features** - share your ideas for new capabilities
### ๐ Getting Started with Contributing
1. **Fork** the repository
2. **Clone** your fork: `git clone https://github.com/YOUR_USERNAME/infra-cost.git`
3. **Create a branch**: `git checkout -b feature/amazing-feature`
4. **Make changes** and write tests
5. **Run quality checks**: `npm run typecheck && npm run lint && npm test`
6. **Commit**: `git commit -m "Add amazing feature"`
7. **Push**: `git push origin feature/amazing-feature`
8. **Create a Pull Request**
### ๐ Contribution Guidelines
- Follow the existing code style and conventions
- Add tests for new features
- Update documentation as needed
- Keep PRs focused on a single feature/fix
- Be respectful and constructive in discussions
### ๐ท๏ธ Good First Issues
Look for issues labeled `good first issue` or `help wanted` to get started!
## ๐ Support & Community
### ๐ฌ Get Help
- **๐ Documentation**: [docs.codecollab.co/infra-cost](https://docs.codecollab.co/infra-cost) *(coming soon)*
- **๐ Bug Reports**: [GitHub Issues](https://github.com/codecollab-co/infra-cost/issues)
- **๐ก Feature Requests**: [GitHub Discussions](https://github.com/codecollab-co/infra-cost/discussions)
- **๐ง Email Support**: support@codecollab.co
### ๐ Show Your Support
If infra-cost helps you save money and optimize costs, please:
- โญ **Star this repository**
- ๐ฆ **Share on Twitter** with #InfraCost #FinOps
- ๐ **Write a review** or blog post about your experience
- ๐ค **Contribute** code, documentation, or feedback
### ๐ข Enterprise Support
For enterprise deployments, custom integrations, and professional support:
- ๐ง Contact: enterprise@codecollab.co
- ๐ SLA-backed support available
- ๐จ Custom branding and whitelabeling
- ๐๏ธ Professional services and consulting
## ๐ License
MIT ยฉ [Code Collab](https://github.com/codecollab-co)
---
## ๐ Changelog
### v0.3.0 - Latest Release
- โ
**GitHub Marketplace Action** - Integrate cost analysis into CI/CD workflows
- โ
**Node.js 20+ support** - Updated runtime requirements
- โ
**Sprint 6 UX improvements** - Enhanced user experience
- โ
**Configuration improvements** - Better config resolution and file permissions
- โ
**Date normalization** - Consistent UTC date handling
### v0.2.4
- โ
**Fixed CommonJS compatibility** - Homebrew installation now works perfectly
- โ
**Enhanced error handling** and user experience improvements
- โ
**Optimized build process** for better performance
### v0.2.0 - Enhanced Features
- โ
**AI-powered anomaly detection** with real-time monitoring
- โ
**Advanced visualization engine** with interactive dashboards
- โ
**PDF report generation** for executives and technical teams
- โ
**Comprehensive Slack integration** with rich formatting
- โ
**Multi-cloud architecture** ready for expansion
- โ
**Enterprise features** including multi-tenancy and API server
### Migration from aws-cost-cli
This tool evolved from `aws-cost-cli` with full backward compatibility. Both `infra-cost` and `aws-cost` commands work seamlessly.
---
**Made with โค๏ธ by [Code Collab](https://github.com/codecollab-co)**
*Empowering teams to optimize cloud costs and build sustainable infrastructure*
[โญ Star us on GitHub](https://github.com/codecollab-co/infra-cost) โข [๐ฆ Follow on Twitter](https://twitter.com/codecollabco) โข [๐ผ LinkedIn](https://linkedin.com/company/codecollab-co)