cloud-cost-cli 0.3.0-beta.1 → 0.3.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -7,6 +7,8 @@
7
7
 
8
8
  A command-line tool that analyzes your AWS and Azure resources to identify cost-saving opportunities — idle resources, oversized instances, unattached volumes, and more.
9
9
 
10
+ **✨ NEW in v0.3.0-beta:** AI-powered explanations and natural language queries!
11
+
10
12
  ---
11
13
 
12
14
  ## The Problem
@@ -34,6 +36,11 @@ Cloud bills are growing faster than revenue. Engineering teams overprovision, fo
34
36
  - ✅ **Multi-cloud support** - AWS and Azure
35
37
  - ✅ **AWS analyzers** - EC2, EBS, RDS, S3, ELB, Elastic IP
36
38
  - ✅ **Azure analyzers** - VMs, Managed Disks, Storage, SQL, Public IPs
39
+ - ✅ **🤖 AI-powered explanations** - Get human-readable explanations for why resources are costing money (beta)
40
+ - ✅ **💬 Natural language queries** - Ask questions like "What's my biggest cost?" or "Show me idle VMs" (beta)
41
+ - ✅ **🔒 Privacy-first AI** - Use local Ollama or cloud OpenAI
42
+ - ✅ **💰 Cost tracking** - Track AI API costs (OpenAI only)
43
+ - ✅ **⚙️ Configuration file** - Save your preferences
37
44
  - ✅ Connect via cloud credentials (read-only recommended)
38
45
  - ✅ Analyze last 7-30 days of usage
39
46
  - ✅ Output top savings opportunities with estimated monthly savings
@@ -44,7 +51,6 @@ Cloud bills are growing faster than revenue. Engineering teams overprovision, fo
44
51
  **Potential future additions:**
45
52
  - GCP support (Compute Engine, Cloud Storage, Cloud SQL)
46
53
  - Real-time pricing API integration
47
- - Configuration file support
48
54
  - Additional AWS services (Lambda, DynamoDB, CloudFront, etc.)
49
55
  - Additional Azure services (App Services, CosmosDB, etc.)
50
56
  - Multi-region analysis
@@ -61,19 +67,34 @@ No commitment on timeline - contributions welcome!
61
67
 
62
68
  **Requirements:**
63
69
  - Node.js >= 18
64
- - Cloud credentials:
65
- - **AWS**: [AWS CLI configured](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) or environment variables
66
- - **Azure**: [Azure CLI logged in](https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli) or environment variables
70
+ - Cloud credentials (choose one per provider):
71
+ - **AWS**:
72
+ - [AWS CLI configured](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) OR
73
+ - Environment variables (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`)
74
+ - **Azure**:
75
+ - [Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli) (`az login`) OR
76
+ - Service Principal (env vars: `AZURE_CLIENT_ID`, `AZURE_CLIENT_SECRET`, `AZURE_TENANT_ID`) OR
77
+ - Managed Identity (for Azure VMs)
78
+ - **Optional for AI features**:
79
+ - OpenAI API key OR
80
+ - [Ollama](https://ollama.ai) installed locally (free, private, runs on your machine)
67
81
 
68
82
  **Install via npm:**
69
83
  ```bash
70
84
  npm install -g cloud-cost-cli
71
85
  ```
72
86
 
87
+ **Try the beta with AI features:**
88
+ ```bash
89
+ npm install -g cloud-cost-cli@beta
90
+ ```
91
+
73
92
  ---
74
93
 
75
94
  ## Usage
76
95
 
96
+ ### Basic Scan
97
+
77
98
  **AWS scan:**
78
99
  ```bash
79
100
  cloud-cost-cli scan --provider aws --profile default --region us-east-1
@@ -81,12 +102,92 @@ cloud-cost-cli scan --provider aws --profile default --region us-east-1
81
102
 
82
103
  **Azure scan:**
83
104
  ```bash
84
- # Set Azure subscription ID (or use --subscription-id flag)
105
+ # Option 1: Azure CLI (easiest for local use)
106
+ az login
85
107
  export AZURE_SUBSCRIPTION_ID="your-subscription-id"
108
+ cloud-cost-cli scan --provider azure --location eastus
86
109
 
110
+ # Option 2: Service Principal (recommended for CI/CD and automation)
111
+ export AZURE_CLIENT_ID="your-app-id"
112
+ export AZURE_CLIENT_SECRET="your-secret"
113
+ export AZURE_TENANT_ID="your-tenant-id"
114
+ export AZURE_SUBSCRIPTION_ID="your-subscription-id"
87
115
  cloud-cost-cli scan --provider azure --location eastus
88
116
  ```
89
117
 
118
+ **How to create Azure Service Principal:**
119
+ ```bash
120
+ # Create service principal with Reader role
121
+ az ad sp create-for-rbac --name "cloud-cost-cli" --role Reader --scopes /subscriptions/YOUR_SUBSCRIPTION_ID
122
+
123
+ # Output will show:
124
+ # {
125
+ # "appId": "xxx", # Use as AZURE_CLIENT_ID
126
+ # "password": "xxx", # Use as AZURE_CLIENT_SECRET
127
+ # "tenant": "xxx" # Use as AZURE_TENANT_ID
128
+ # }
129
+ ```
130
+
131
+ ### 🤖 AI-Powered Features (Beta)
132
+
133
+ **Get AI explanations for opportunities:**
134
+ ```bash
135
+ # Using OpenAI (requires API key)
136
+ export OPENAI_API_KEY="sk-..."
137
+ cloud-cost-cli scan --provider aws --region us-east-1 --explain
138
+
139
+ # Using local Ollama (free, private, no API key needed)
140
+ cloud-cost-cli scan --provider aws --region us-east-1 --explain --ai-provider ollama
141
+ ```
142
+
143
+ **Ask natural language questions:**
144
+ ```bash
145
+ # First, run a scan to collect data
146
+ cloud-cost-cli scan --provider aws --region us-east-1
147
+
148
+ # Then ask questions about your costs
149
+ cloud-cost-cli ask "What's my biggest cost opportunity?"
150
+ cloud-cost-cli ask "Show me all idle EC2 instances"
151
+ cloud-cost-cli ask "How much can I save on storage?"
152
+ cloud-cost-cli ask "Which resources should I optimize first?"
153
+ ```
154
+
155
+ **Configure AI settings (saves preferences):**
156
+ ```bash
157
+ # Initialize config file
158
+ cloud-cost-cli config init
159
+
160
+ # Set AI provider (openai or ollama)
161
+ cloud-cost-cli config set ai.provider ollama
162
+
163
+ # Set OpenAI API key (if using OpenAI)
164
+ cloud-cost-cli config set ai.apiKey "sk-..."
165
+
166
+ # Set AI model
167
+ cloud-cost-cli config set ai.model "llama3.1:8b" # For Ollama
168
+ cloud-cost-cli config set ai.model "gpt-4o-mini" # For OpenAI
169
+
170
+ # Set max explanations (how many to explain)
171
+ cloud-cost-cli config set ai.maxExplanations 5
172
+
173
+ # View your config
174
+ cloud-cost-cli config show
175
+ ```
176
+
177
+ **Track AI costs (OpenAI only):**
178
+ ```bash
179
+ # View AI API costs
180
+ cloud-cost-cli costs
181
+
182
+ # View last 7 days
183
+ cloud-cost-cli costs --days 7
184
+
185
+ # Clear cost tracking
186
+ cloud-cost-cli costs --clear
187
+ ```
188
+
189
+ ### Advanced Options
190
+
90
191
  **Show more opportunities:**
91
192
  ```bash
92
193
  cloud-cost-cli scan --provider aws --top 20 # Show top 20 instead of default 5
@@ -102,7 +203,7 @@ cloud-cost-cli scan --provider azure --min-savings 50 # Only show opportunities
102
203
  cloud-cost-cli scan --provider aws --output json > report.json
103
204
  ```
104
205
 
105
- **Example output:**
206
+ **Example output (with AI explanations):**
106
207
  ```
107
208
  Cloud Cost Optimization Report
108
209
  Provider: AWS | Region: us-east-1 | Account: N/A
@@ -118,18 +219,114 @@ Top 5 Savings Opportunities (est. $1,245/month):
118
219
  │ 2 │ EBS │ vol-0xyz789abc │ Delete unattached volume (500 GB) │ $40.00 │
119
220
  ├───┼──────────┼────────────────────────────────────────┼──────────────────────────────────────────────────────────┼─────────────┤
120
221
  │ 3 │ RDS │ mydb-production │ Downsize from db.r5.xlarge to db.t3.large (CPU: 15%) │ $180.00 │
121
- ├───┼──────────┼────────────────────────────────────────┼──────────────────────────────────────────────────────────┼─────────────┤
122
- │ 4 │ ELB │ my-old-alb │ Delete unused load balancer │ $22.00 │
123
- ├───┼──────────┼────────────────────────────────────────┼──────────────────────────────────────────────────────────┼─────────────┤
124
- │ 5 │ S3 │ logs-bucket-2023 │ Add lifecycle policy to transition to Glacier │ $938.00 │
125
222
  └───┴──────────┴────────────────────────────────────────┴──────────────────────────────────────────────────────────┴─────────────┘
126
223
 
224
+ 🤖 AI Explanations:
225
+
226
+ 💡 Opportunity #1: Stop idle instance (CPU: 2%)
227
+ This EC2 instance is consuming only 2% CPU, indicating it's severely underutilized.
228
+ Consider stopping it during off-hours or right-sizing to a smaller instance type.
229
+ Quick win: Stop it immediately if it's a dev/test server not actively used.
230
+ Risk: Low - monitor for 24h first to confirm usage patterns.
231
+
232
+ 💡 Opportunity #2: Delete unattached volume (500 GB)
233
+ This EBS volume isn't attached to any instance but you're still paying for storage.
234
+ Either delete it if data isn't needed, or create a snapshot first for backup.
235
+ Quick win: Take a snapshot ($0.05/GB/mo vs $0.08/GB/mo), then delete the volume.
236
+ Risk: Medium - verify no one needs this data before deleting.
237
+
238
+ 💡 Opportunity #3: Downsize RDS instance
239
+ Your database is only using 15% CPU on a db.r5.xlarge. You're paying for 4 vCPUs
240
+ but only need 1-2. Downsize to db.t3.large (2 vCPUs) and save $180/month.
241
+ Quick win: Schedule a downsize during your next maintenance window.
242
+ Risk: Low-Medium - test query performance after resize.
243
+
127
244
  Total potential savings: $1,245/month ($14,940/year)
128
245
 
129
- Summary: 47 resources analyzed | 12 idle | 8 oversized | 5 unused
246
+ AI explanations powered by OpenAI GPT-4o-mini (cost: $0.02)
247
+ ```
248
+
249
+ ---
250
+
251
+ ## AI Features Setup
252
+
253
+ ### Option 1: OpenAI (Cloud, Paid)
254
+
255
+ **Pros:** Fast, accurate, works anywhere
256
+ **Cons:** Costs ~$0.01-0.05 per scan, data sent to OpenAI
257
+
258
+ ```bash
259
+ # Get API key from https://platform.openai.com/api-keys
260
+ export OPENAI_API_KEY="sk-..."
261
+
262
+ # Or save to config
263
+ cloud-cost-cli config set ai.apiKey "sk-..."
264
+ cloud-cost-cli config set ai.provider openai
265
+ ```
266
+
267
+ ### Option 2: Ollama (Local, Free)
130
268
 
131
- 💡 Note: Cost estimates based on us-east-1 pricing and may vary by region.
132
- For more accurate estimates, actual costs depend on your usage and region.
269
+ **Pros:** Free, private (runs on your machine), no API costs
270
+ **Cons:** Requires ~4GB RAM, slower than OpenAI
271
+
272
+ ```bash
273
+ # Install Ollama
274
+ curl -fsSL https://ollama.ai/install.sh | sh
275
+
276
+ # Pull a model (one-time, ~4GB download)
277
+ ollama pull llama3.1:8b
278
+
279
+ # Configure cloud-cost-cli
280
+ cloud-cost-cli config set ai.provider ollama
281
+ cloud-cost-cli config set ai.model "llama3.1:8b"
282
+
283
+ # Use it
284
+ cloud-cost-cli scan --provider aws --region us-east-1 --explain
285
+ ```
286
+
287
+ **Recommended Ollama models:**
288
+ - `llama3.1:8b` - Best balance (4GB RAM, good quality)
289
+ - `llama3.2:3b` - Faster, less RAM (2GB, slightly lower quality)
290
+ - `mistral:7b` - Alternative, similar to llama3.1
291
+
292
+ ---
293
+
294
+ ## Configuration File
295
+
296
+ **Location:** `~/.cloud-cost-cli.json`
297
+
298
+ **Example config:**
299
+ ```json
300
+ {
301
+ "ai": {
302
+ "provider": "ollama",
303
+ "model": "llama3.1:8b",
304
+ "maxExplanations": 5,
305
+ "cache": {
306
+ "enabled": true,
307
+ "ttlDays": 7
308
+ }
309
+ },
310
+ "scan": {
311
+ "defaultProvider": "aws",
312
+ "defaultRegion": "us-east-1",
313
+ "defaultTop": 5,
314
+ "minSavings": 10
315
+ },
316
+ "aws": {
317
+ "profile": "default",
318
+ "region": "us-east-1"
319
+ }
320
+ }
321
+ ```
322
+
323
+ **Manage config:**
324
+ ```bash
325
+ cloud-cost-cli config init # Create config file
326
+ cloud-cost-cli config show # View current config
327
+ cloud-cost-cli config get ai.provider # Get specific value
328
+ cloud-cost-cli config set ai.provider ollama # Set value
329
+ cloud-cost-cli config path # Show config file location
133
330
  ```
134
331
 
135
332
  ---
@@ -208,6 +405,8 @@ MIT License - see [LICENSE](LICENSE)
208
405
  - [Commander.js](https://github.com/tj/commander.js) - CLI framework
209
406
  - [cli-table3](https://github.com/cli-table/cli-table3) - Terminal tables
210
407
  - [Chalk](https://github.com/chalk/chalk) - Terminal styling
408
+ - [OpenAI API](https://platform.openai.com/) - AI explanations
409
+ - [Ollama](https://ollama.ai) - Local AI models
211
410
 
212
411
  ---
213
412
 
@@ -224,9 +423,20 @@ A: Read-only permissions for each cloud provider:
224
423
  **Q: How accurate are the savings estimates?**
225
424
  A: Estimates are based on current pricing and usage patterns. Actual savings may vary by region and your specific pricing agreements (Reserved Instances, Savings Plans, etc.).
226
425
 
426
+ **Q: Is my data sent to OpenAI?**
427
+ A: Only if you use `--ai-provider openai` (the default). Resource metadata and recommendations are sent to OpenAI's API to generate explanations. If you want complete privacy, use `--ai-provider ollama` which runs 100% locally on your machine.
428
+
429
+ **Q: How much do AI features cost?**
430
+ A:
431
+ - **Ollama**: Free! Runs locally, no API costs
432
+ - **OpenAI**: ~$0.01-0.05 per scan (GPT-4o-mini). Use `cloud-cost-cli costs` to track spending.
433
+
227
434
  **Q: Can I run this in CI/CD?**
228
435
  A: Yes. Use `--output json` and parse the results to fail builds if savings exceed a threshold.
229
436
 
437
+ **Q: Do I need AI features to use the tool?**
438
+ A: No! AI features are completely optional. The core cost scanning works without any AI setup.
439
+
230
440
  ---
231
441
 
232
442
  **Star this repo if it saves you money!** ⭐
@@ -172,6 +172,14 @@ async function scanAzure(options) {
172
172
  else {
173
173
  (0, logger_1.info)('Scanning all locations (no filter specified)');
174
174
  }
175
+ // Test Azure credentials before scanning
176
+ try {
177
+ await client.testConnection();
178
+ }
179
+ catch (err) {
180
+ (0, logger_1.error)(err.message);
181
+ process.exit(1);
182
+ }
175
183
  if (options.accurate) {
176
184
  (0, logger_1.info)('Note: --accurate flag is not yet implemented. Using estimated pricing.');
177
185
  }
@@ -12,6 +12,7 @@ export declare class AzureClient {
12
12
  subscriptionId: string;
13
13
  location: string;
14
14
  constructor(config?: AzureClientConfig);
15
+ testConnection(): Promise<void>;
15
16
  getComputeClient(): ComputeManagementClient;
16
17
  getStorageClient(): StorageManagementClient;
17
18
  getSqlClient(): SqlManagementClient;
@@ -22,6 +22,29 @@ class AzureClient {
22
22
  // Default to East US if no location specified
23
23
  this.location = config.location || '';
24
24
  }
25
+ // Test Azure credentials by making a lightweight API call
26
+ async testConnection() {
27
+ try {
28
+ const computeClient = this.getComputeClient();
29
+ // Try to list VMs (we'll just get an iterator, not actually iterate)
30
+ const vmsIterator = computeClient.virtualMachines.listAll();
31
+ // Get first page to test auth
32
+ await vmsIterator.next();
33
+ }
34
+ catch (error) {
35
+ const errorMsg = error.message || '';
36
+ if (errorMsg.includes('No subscriptions found') ||
37
+ errorMsg.includes('authentication') ||
38
+ errorMsg.includes('credentials') ||
39
+ errorMsg.includes('login') ||
40
+ error.statusCode === 401 ||
41
+ error.code === 'CredentialUnavailableError') {
42
+ throw new Error('Azure authentication failed. Please run "az login" first or set up service principal credentials.\n' +
43
+ 'See: https://learn.microsoft.com/en-us/cli/azure/authenticate-azure-cli');
44
+ }
45
+ throw error;
46
+ }
47
+ }
25
48
  getComputeClient() {
26
49
  return new arm_compute_1.ComputeManagementClient(this.credential, this.subscriptionId);
27
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cloud-cost-cli",
3
- "version": "0.3.0-beta.1",
3
+ "version": "0.3.0-beta.2",
4
4
  "description": "Optimize your cloud spend in seconds",
5
5
  "main": "dist/index.js",
6
6
  "bin": {