cloud-cost-cli 0.1.0 → 0.2.0
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 +119 -122
- package/dist/bin/cloud-cost-cli.js +5 -2
- package/dist/src/analyzers/cost-estimator.d.ts +14 -0
- package/dist/src/analyzers/cost-estimator.js +74 -16
- package/dist/src/analyzers/pricing-service.d.ts +38 -0
- package/dist/src/analyzers/pricing-service.js +263 -0
- package/dist/src/commands/scan.d.ts +3 -0
- package/dist/src/commands/scan.js +173 -86
- package/dist/src/providers/aws/client.d.ts +1 -0
- package/dist/src/providers/aws/client.js +60 -1
- package/dist/src/providers/azure/client.d.ts +20 -0
- package/dist/src/providers/azure/client.js +41 -0
- package/dist/src/providers/azure/disks.d.ts +4 -0
- package/dist/src/providers/azure/disks.js +87 -0
- package/dist/src/providers/azure/index.d.ts +6 -0
- package/dist/src/providers/azure/index.js +15 -0
- package/dist/src/providers/azure/public-ips.d.ts +3 -0
- package/dist/src/providers/azure/public-ips.js +47 -0
- package/dist/src/providers/azure/sql.d.ts +4 -0
- package/dist/src/providers/azure/sql.js +134 -0
- package/dist/src/providers/azure/storage.d.ts +8 -0
- package/dist/src/providers/azure/storage.js +100 -0
- package/dist/src/providers/azure/vms.d.ts +4 -0
- package/dist/src/providers/azure/vms.js +164 -0
- package/dist/src/reporters/table.js +3 -1
- package/dist/src/utils/formatter.d.ts +2 -0
- package/dist/src/utils/formatter.js +29 -1
- package/docs/RELEASE.md +14 -22
- package/package.json +12 -2
package/README.md
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# cloud-cost-cli
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/cloud-cost-cli)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
3
6
|
**Optimize your cloud spend in seconds.**
|
|
4
7
|
|
|
5
|
-
A command-line tool that analyzes your AWS
|
|
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.
|
|
6
9
|
|
|
7
10
|
---
|
|
8
11
|
|
|
@@ -15,157 +18,140 @@ Cloud bills are growing faster than revenue. Engineering teams overprovision, fo
|
|
|
15
18
|
`cloud-cost-cli` connects to your cloud accounts, analyzes resource usage and billing data, and outputs a ranked list of actionable savings opportunities — all in your terminal, in under 60 seconds.
|
|
16
19
|
|
|
17
20
|
**What it finds:**
|
|
18
|
-
- Idle EC2
|
|
19
|
-
- Unattached
|
|
20
|
-
- Oversized
|
|
21
|
+
- Idle VMs/EC2 instances (low CPU, stopped but still billed)
|
|
22
|
+
- Unattached volumes, disks, and snapshots
|
|
23
|
+
- Oversized database instances (RDS, Azure SQL)
|
|
21
24
|
- Old load balancers with no traffic
|
|
22
|
-
- Unused
|
|
23
|
-
- Underutilized
|
|
24
|
-
-
|
|
25
|
+
- Unused public IP addresses
|
|
26
|
+
- Underutilized resources that can be downsized
|
|
27
|
+
- Storage without lifecycle policies
|
|
25
28
|
|
|
26
29
|
---
|
|
27
30
|
|
|
28
|
-
## Features
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
- ✅
|
|
32
|
-
- ✅
|
|
33
|
-
- ✅
|
|
34
|
-
- ✅
|
|
35
|
-
- ✅
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
-
|
|
39
|
-
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
-
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
**Current capabilities:**
|
|
34
|
+
- ✅ **Multi-cloud support** - AWS and Azure
|
|
35
|
+
- ✅ **AWS analyzers** - EC2, EBS, RDS, S3, ELB, Elastic IP
|
|
36
|
+
- ✅ **Azure analyzers** - VMs, Managed Disks, Storage, SQL, Public IPs
|
|
37
|
+
- ✅ Connect via cloud credentials (read-only recommended)
|
|
38
|
+
- ✅ Analyze last 7-30 days of usage
|
|
39
|
+
- ✅ Output top savings opportunities with estimated monthly savings
|
|
40
|
+
- ✅ Export report as JSON or terminal table
|
|
41
|
+
- ✅ Filter by minimum savings amount
|
|
42
|
+
- ✅ Comprehensive test suite (84 tests)
|
|
43
|
+
|
|
44
|
+
**Potential future additions:**
|
|
45
|
+
- GCP support (Compute Engine, Cloud Storage, Cloud SQL)
|
|
46
|
+
- Real-time pricing API integration
|
|
47
|
+
- Configuration file support
|
|
48
|
+
- Additional AWS services (Lambda, DynamoDB, CloudFront, etc.)
|
|
49
|
+
- Additional Azure services (App Services, CosmosDB, etc.)
|
|
50
|
+
- Multi-region analysis
|
|
51
|
+
- Historical cost tracking
|
|
52
|
+
- Scheduled scans and notifications
|
|
53
|
+
- CI/CD integration examples
|
|
54
|
+
- Custom analyzer rules
|
|
55
|
+
|
|
56
|
+
No commitment on timeline - contributions welcome!
|
|
44
57
|
|
|
45
58
|
---
|
|
46
59
|
|
|
47
60
|
## Installation
|
|
48
61
|
|
|
49
62
|
**Requirements:**
|
|
50
|
-
- Node.js >= 18
|
|
51
|
-
-
|
|
63
|
+
- 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
|
|
52
67
|
|
|
53
68
|
**Install via npm:**
|
|
54
69
|
```bash
|
|
55
70
|
npm install -g cloud-cost-cli
|
|
56
71
|
```
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
```bash
|
|
60
|
-
# macOS/Linux
|
|
61
|
-
curl -L https://github.com/vuhp/cloud-cost-cli/releases/latest/download/cloud-cost-cli-$(uname -s)-$(uname -m) -o /usr/local/bin/cloud-cost-cli
|
|
62
|
-
chmod +x /usr/local/bin/cloud-cost-cli
|
|
73
|
+
---
|
|
63
74
|
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
## Usage
|
|
76
|
+
|
|
77
|
+
**AWS scan:**
|
|
78
|
+
```bash
|
|
79
|
+
cloud-cost-cli scan --provider aws --profile default --region us-east-1
|
|
66
80
|
```
|
|
67
81
|
|
|
68
|
-
|
|
82
|
+
**Azure scan:**
|
|
83
|
+
```bash
|
|
84
|
+
# Set Azure subscription ID (or use --subscription-id flag)
|
|
85
|
+
export AZURE_SUBSCRIPTION_ID="your-subscription-id"
|
|
69
86
|
|
|
70
|
-
|
|
87
|
+
cloud-cost-cli scan --provider azure --location eastus
|
|
88
|
+
```
|
|
71
89
|
|
|
72
|
-
**
|
|
90
|
+
**Show more opportunities:**
|
|
73
91
|
```bash
|
|
74
|
-
cloud-cost-cli scan --provider aws --
|
|
92
|
+
cloud-cost-cli scan --provider aws --top 20 # Show top 20 instead of default 5
|
|
75
93
|
```
|
|
76
94
|
|
|
77
|
-
**
|
|
95
|
+
**Filter by minimum savings:**
|
|
78
96
|
```bash
|
|
79
|
-
cloud-cost-cli scan --provider
|
|
97
|
+
cloud-cost-cli scan --provider azure --min-savings 50 # Only show opportunities > $50/month
|
|
80
98
|
```
|
|
81
99
|
|
|
82
|
-
**
|
|
100
|
+
**Specify output format:**
|
|
83
101
|
```bash
|
|
84
|
-
cloud-cost-cli scan --provider aws --
|
|
102
|
+
cloud-cost-cli scan --provider aws --output json > report.json
|
|
85
103
|
```
|
|
86
104
|
|
|
87
105
|
**Example output:**
|
|
88
106
|
```
|
|
89
107
|
Cloud Cost Optimization Report
|
|
90
|
-
Provider: AWS | Region: us-east-1 | Account:
|
|
108
|
+
Provider: AWS | Region: us-east-1 | Account: N/A
|
|
91
109
|
Analyzed: 2026-01-01 to 2026-01-31
|
|
92
110
|
|
|
93
111
|
Top 5 Savings Opportunities (est. $1,245/month):
|
|
94
112
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
2
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
→ Est. savings: $180/month
|
|
113
|
+
┌───┬──────────┬────────────────────────────────────────┬──────────────────────────────────────────────────────────┬─────────────┐
|
|
114
|
+
│ # │ Type │ Resource ID │ Recommendation │ Savings/mo │
|
|
115
|
+
├───┼──────────┼────────────────────────────────────────┼──────────────────────────────────────────────────────────┼─────────────┤
|
|
116
|
+
│ 1 │ EC2 │ i-0abc123def456 │ Stop idle instance (CPU: 2%) │ $65.00 │
|
|
117
|
+
├───┼──────────┼────────────────────────────────────────┼──────────────────────────────────────────────────────────┼─────────────┤
|
|
118
|
+
│ 2 │ EBS │ vol-0xyz789abc │ Delete unattached volume (500 GB) │ $40.00 │
|
|
119
|
+
├───┼──────────┼────────────────────────────────────────┼──────────────────────────────────────────────────────────┼─────────────┤
|
|
120
|
+
│ 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
|
+
└───┴──────────┴────────────────────────────────────────┴──────────────────────────────────────────────────────────┴─────────────┘
|
|
109
126
|
|
|
110
|
-
|
|
111
|
-
Active targets: 0 | Requests/day: 0
|
|
112
|
-
→ Recommendation: Delete
|
|
113
|
-
→ Est. savings: $22/month
|
|
127
|
+
Total potential savings: $1,245/month ($14,940/year)
|
|
114
128
|
|
|
115
|
-
|
|
116
|
-
Size: 12 TB | Age: 18 months
|
|
117
|
-
→ Recommendation: Enable Intelligent-Tiering or Glacier transition
|
|
118
|
-
→ Est. savings: $938/month
|
|
129
|
+
Summary: 47 resources analyzed | 12 idle | 8 oversized | 5 unused
|
|
119
130
|
|
|
120
|
-
|
|
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.
|
|
121
133
|
```
|
|
122
134
|
|
|
123
135
|
---
|
|
124
136
|
|
|
125
|
-
##
|
|
126
|
-
|
|
127
|
-
Create a config file at `~/.cloud-cost-cli/config.json` (optional):
|
|
128
|
-
|
|
129
|
-
```json
|
|
130
|
-
{
|
|
131
|
-
"aws": {
|
|
132
|
-
"profile": "default",
|
|
133
|
-
"regions": ["us-east-1", "us-west-2"],
|
|
134
|
-
"excludeResources": ["i-0abc123", "vol-xyz"],
|
|
135
|
-
"thresholds": {
|
|
136
|
-
"idleCpuPercent": 5,
|
|
137
|
-
"minAgeDays": 7
|
|
138
|
-
}
|
|
139
|
-
},
|
|
140
|
-
"output": {
|
|
141
|
-
"format": "table",
|
|
142
|
-
"includeRecommendations": true
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
```
|
|
137
|
+
## Pricing Estimates
|
|
146
138
|
|
|
147
|
-
|
|
139
|
+
**How cost estimates work:**
|
|
148
140
|
|
|
149
|
-
|
|
141
|
+
Cost savings are estimated using AWS on-demand pricing for **us-east-1** (January 2026). These are approximations to help you prioritize optimization efforts.
|
|
150
142
|
|
|
151
|
-
**
|
|
152
|
-
-
|
|
153
|
-
-
|
|
154
|
-
-
|
|
155
|
-
-
|
|
143
|
+
**Important notes:**
|
|
144
|
+
- 💵 Actual costs vary by region (e.g., ap-southeast-1 may be 10-15% higher)
|
|
145
|
+
- 📊 Estimates don't include Reserved Instances, Savings Plans, or spot discounts
|
|
146
|
+
- 🔄 AWS pricing changes periodically
|
|
147
|
+
- ⚙️ Additional costs like data transfer and storage operations not included
|
|
156
148
|
|
|
157
|
-
**
|
|
158
|
-
-
|
|
159
|
-
-
|
|
160
|
-
-
|
|
161
|
-
- Slack webhook integration
|
|
162
|
-
- GitHub Sponsors perks (early access, priority support)
|
|
149
|
+
**For the most accurate estimates:**
|
|
150
|
+
- Cross-reference with your AWS Cost Explorer or Azure Cost Management
|
|
151
|
+
- Consider estimates as directional guidance, not exact amounts
|
|
152
|
+
- Real-time pricing API integration coming in a future release
|
|
163
153
|
|
|
164
|
-
|
|
165
|
-
- SaaS version: connect account, weekly email reports, team dashboard
|
|
166
|
-
- Paid tiers: $29/mo (alerts + history), $99/mo (multi-account + API)
|
|
167
|
-
- Enterprise: on-prem, SSO, audit logs, custom rules
|
|
168
|
-
- Terraform provider (flag cost risks before apply)
|
|
154
|
+
The goal is to help you find waste quickly — even if estimates are ±20%, you'll still identify significant savings opportunities.
|
|
169
155
|
|
|
170
156
|
---
|
|
171
157
|
|
|
@@ -178,25 +164,33 @@ Contributions welcome! Please open an issue before submitting large PRs.
|
|
|
178
164
|
git clone https://github.com/vuhp/cloud-cost-cli.git
|
|
179
165
|
cd cloud-cost-cli
|
|
180
166
|
npm install
|
|
181
|
-
npm run
|
|
167
|
+
npm run build
|
|
182
168
|
```
|
|
183
169
|
|
|
184
170
|
**Run tests:**
|
|
185
171
|
```bash
|
|
186
|
-
npm test
|
|
172
|
+
npm test # Run all tests
|
|
173
|
+
npm run test:coverage # Run with coverage report
|
|
174
|
+
npm run test:ui # Interactive UI
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
**Development workflow:**
|
|
178
|
+
```bash
|
|
179
|
+
npm run dev -- scan --provider aws --profile your-profile # Test locally
|
|
180
|
+
npm run build # Compile TypeScript
|
|
187
181
|
```
|
|
188
182
|
|
|
189
183
|
---
|
|
190
184
|
|
|
191
|
-
##
|
|
185
|
+
## Support This Project
|
|
192
186
|
|
|
193
|
-
If
|
|
187
|
+
If cloud-cost-cli helps you save money, consider [sponsoring on GitHub](https://github.com/sponsors/vuhp).
|
|
194
188
|
|
|
195
|
-
|
|
196
|
-
-
|
|
197
|
-
-
|
|
198
|
-
-
|
|
199
|
-
-
|
|
189
|
+
Your support helps fund:
|
|
190
|
+
- 🚀 New cloud provider integrations
|
|
191
|
+
- 🐛 Bug fixes and maintenance
|
|
192
|
+
- 📚 Better documentation
|
|
193
|
+
- ✨ Community feature requests
|
|
200
194
|
|
|
201
195
|
---
|
|
202
196
|
|
|
@@ -208,27 +202,30 @@ MIT License - see [LICENSE](LICENSE)
|
|
|
208
202
|
|
|
209
203
|
## Credits
|
|
210
204
|
|
|
211
|
-
**
|
|
212
|
-
- AWS SDK for JavaScript
|
|
213
|
-
-
|
|
214
|
-
-
|
|
215
|
-
-
|
|
205
|
+
**Built with:**
|
|
206
|
+
- [AWS SDK for JavaScript v3](https://aws.amazon.com/sdk-for-javascript/) - AWS cloud APIs
|
|
207
|
+
- [Azure SDK for JavaScript](https://azure.github.io/azure-sdk-for-js/) - Azure cloud APIs
|
|
208
|
+
- [Commander.js](https://github.com/tj/commander.js) - CLI framework
|
|
209
|
+
- [cli-table3](https://github.com/cli-table/cli-table3) - Terminal tables
|
|
210
|
+
- [Chalk](https://github.com/chalk/chalk) - Terminal styling
|
|
216
211
|
|
|
217
212
|
---
|
|
218
213
|
|
|
219
214
|
## FAQ
|
|
220
215
|
|
|
221
216
|
**Q: Does this tool make changes to my infrastructure?**
|
|
222
|
-
A: No. It only reads
|
|
217
|
+
A: No. It only reads resource metadata and usage metrics. It never modifies or deletes resources.
|
|
223
218
|
|
|
224
|
-
**Q: What
|
|
225
|
-
A: Read-only permissions for
|
|
219
|
+
**Q: What permissions are required?**
|
|
220
|
+
A: Read-only permissions for each cloud provider:
|
|
221
|
+
- **AWS**: EC2, EBS, RDS, S3, ELB, CloudWatch (see [AWS permissions](https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies.html))
|
|
222
|
+
- **Azure**: Reader role on subscription or resource groups
|
|
226
223
|
|
|
227
224
|
**Q: How accurate are the savings estimates?**
|
|
228
|
-
A: Estimates are based on current pricing and usage patterns. Actual savings may vary.
|
|
225
|
+
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.).
|
|
229
226
|
|
|
230
227
|
**Q: Can I run this in CI/CD?**
|
|
231
|
-
A: Yes. Use `--output json` and
|
|
228
|
+
A: Yes. Use `--output json` and parse the results to fail builds if savings exceed a threshold.
|
|
232
229
|
|
|
233
230
|
---
|
|
234
231
|
|
|
@@ -11,13 +11,16 @@ program
|
|
|
11
11
|
program
|
|
12
12
|
.command('scan')
|
|
13
13
|
.description('Scan cloud account for cost savings')
|
|
14
|
-
.option('--provider <aws|
|
|
15
|
-
.option('--region <region>', '
|
|
14
|
+
.option('--provider <aws|azure>', 'Cloud provider', 'aws')
|
|
15
|
+
.option('--region <region>', 'AWS region (e.g., us-east-1)')
|
|
16
16
|
.option('--profile <profile>', 'AWS profile name', 'default')
|
|
17
|
+
.option('--subscription-id <id>', 'Azure subscription ID')
|
|
18
|
+
.option('--location <location>', 'Azure location filter (e.g., eastus, westus2) - optional, scans all if omitted')
|
|
17
19
|
.option('--top <N>', 'Show top N opportunities', '5')
|
|
18
20
|
.option('--output <table|json|markdown>', 'Output format', 'table')
|
|
19
21
|
.option('--days <N>', 'Analysis period in days', '30')
|
|
20
22
|
.option('--min-savings <amount>', 'Filter by minimum savings ($/month)')
|
|
23
|
+
.option('--accurate', 'Use real-time pricing from AWS (slower but more accurate)')
|
|
21
24
|
.option('--verbose', 'Verbose logging')
|
|
22
25
|
.action(scan_js_1.scanCommand);
|
|
23
26
|
program.parse();
|
|
@@ -13,6 +13,20 @@ export declare const ELB_PRICING: {
|
|
|
13
13
|
clb: number;
|
|
14
14
|
};
|
|
15
15
|
export declare const EIP_PRICING_HOURLY = 0.005;
|
|
16
|
+
/**
|
|
17
|
+
* Cost estimator with support for both estimate and accurate modes
|
|
18
|
+
*/
|
|
19
|
+
export declare class CostEstimator {
|
|
20
|
+
private pricingService?;
|
|
21
|
+
private useAccuratePricing;
|
|
22
|
+
constructor(region: string, accurate?: boolean);
|
|
23
|
+
getEC2MonthlyCost(instanceType: string): Promise<number>;
|
|
24
|
+
getEBSMonthlyCost(sizeGB: number, volumeType: string): Promise<number>;
|
|
25
|
+
getRDSMonthlyCost(instanceClass: string, engine?: string): Promise<number>;
|
|
26
|
+
getS3MonthlyCost(sizeGB: number, storageClass?: string): number;
|
|
27
|
+
getELBMonthlyCost(type?: 'alb' | 'nlb' | 'clb'): number;
|
|
28
|
+
getEIPMonthlyCost(): number;
|
|
29
|
+
}
|
|
16
30
|
export declare function getEC2MonthlyCost(instanceType: string): number;
|
|
17
31
|
export declare function getEBSMonthlyCost(sizeGB: number, volumeType: string): number;
|
|
18
32
|
export declare function getRDSMonthlyCost(instanceClass: string): number;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// EC2 instance pricing (us-east-1, Linux, on-demand, monthly estimate)
|
|
3
|
-
// Source: AWS pricing as of 2026-01, monthly = hourly × 730
|
|
4
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
-
exports.EIP_PRICING_HOURLY = exports.ELB_PRICING = exports.S3_PRICING = exports.RDS_PRICING = exports.EBS_PRICING = exports.EC2_PRICING = void 0;
|
|
3
|
+
exports.CostEstimator = exports.EIP_PRICING_HOURLY = exports.ELB_PRICING = exports.S3_PRICING = exports.RDS_PRICING = exports.EBS_PRICING = exports.EC2_PRICING = void 0;
|
|
6
4
|
exports.getEC2MonthlyCost = getEC2MonthlyCost;
|
|
7
5
|
exports.getEBSMonthlyCost = getEBSMonthlyCost;
|
|
8
6
|
exports.getRDSMonthlyCost = getRDSMonthlyCost;
|
|
9
7
|
exports.getS3MonthlyCost = getS3MonthlyCost;
|
|
10
8
|
exports.getELBMonthlyCost = getELBMonthlyCost;
|
|
11
9
|
exports.getEIPMonthlyCost = getEIPMonthlyCost;
|
|
10
|
+
const pricing_service_1 = require("./pricing-service");
|
|
11
|
+
// Fallback pricing estimates (based on us-east-1, Jan 2026)
|
|
12
|
+
// Used when --accurate flag is not set or Pricing API fails
|
|
12
13
|
exports.EC2_PRICING = {
|
|
13
14
|
't2.micro': 8.47,
|
|
14
15
|
't2.small': 16.79,
|
|
@@ -28,7 +29,6 @@ exports.EC2_PRICING = {
|
|
|
28
29
|
'r5.large': 91.25,
|
|
29
30
|
'r5.xlarge': 182.50,
|
|
30
31
|
};
|
|
31
|
-
// EBS pricing (us-east-1, per GB/month)
|
|
32
32
|
exports.EBS_PRICING = {
|
|
33
33
|
gp3: 0.08,
|
|
34
34
|
gp2: 0.10,
|
|
@@ -37,7 +37,6 @@ exports.EBS_PRICING = {
|
|
|
37
37
|
st1: 0.045,
|
|
38
38
|
sc1: 0.015,
|
|
39
39
|
};
|
|
40
|
-
// RDS pricing (us-east-1, per month)
|
|
41
40
|
exports.RDS_PRICING = {
|
|
42
41
|
'db.t3.micro': 11.01,
|
|
43
42
|
'db.t3.small': 22.63,
|
|
@@ -49,30 +48,89 @@ exports.RDS_PRICING = {
|
|
|
49
48
|
'db.r5.xlarge': 350.40,
|
|
50
49
|
'db.r5.2xlarge': 700.80,
|
|
51
50
|
};
|
|
52
|
-
// S3 pricing (per GB/month)
|
|
53
51
|
exports.S3_PRICING = {
|
|
54
52
|
standard: 0.023,
|
|
55
|
-
intelligentTiering: 0.023,
|
|
53
|
+
intelligentTiering: 0.023,
|
|
56
54
|
glacier: 0.004,
|
|
57
55
|
glacierDeepArchive: 0.00099,
|
|
58
56
|
};
|
|
59
|
-
// ELB pricing (per month, excluding LCU charges)
|
|
60
57
|
exports.ELB_PRICING = {
|
|
61
|
-
alb: 16.43,
|
|
62
|
-
nlb: 16.43,
|
|
63
|
-
clb: 18.25,
|
|
58
|
+
alb: 16.43,
|
|
59
|
+
nlb: 16.43,
|
|
60
|
+
clb: 18.25,
|
|
64
61
|
};
|
|
65
|
-
|
|
66
|
-
|
|
62
|
+
exports.EIP_PRICING_HOURLY = 0.005;
|
|
63
|
+
/**
|
|
64
|
+
* Cost estimator with support for both estimate and accurate modes
|
|
65
|
+
*/
|
|
66
|
+
class CostEstimator {
|
|
67
|
+
pricingService;
|
|
68
|
+
useAccuratePricing;
|
|
69
|
+
constructor(region, accurate = false) {
|
|
70
|
+
this.useAccuratePricing = accurate;
|
|
71
|
+
if (accurate) {
|
|
72
|
+
this.pricingService = new pricing_service_1.PricingService(region);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async getEC2MonthlyCost(instanceType) {
|
|
76
|
+
if (this.useAccuratePricing && this.pricingService) {
|
|
77
|
+
try {
|
|
78
|
+
return await this.pricingService.getEC2Price(instanceType);
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
// Fallback to estimate if API fails
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return exports.EC2_PRICING[instanceType] || 50; // Generic estimate if type unknown
|
|
85
|
+
}
|
|
86
|
+
async getEBSMonthlyCost(sizeGB, volumeType) {
|
|
87
|
+
let pricePerGB;
|
|
88
|
+
if (this.useAccuratePricing && this.pricingService) {
|
|
89
|
+
try {
|
|
90
|
+
pricePerGB = await this.pricingService.getEBSPrice(volumeType);
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
pricePerGB = exports.EBS_PRICING[volumeType] || 0.08;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
pricePerGB = exports.EBS_PRICING[volumeType] || 0.08;
|
|
98
|
+
}
|
|
99
|
+
return sizeGB * pricePerGB;
|
|
100
|
+
}
|
|
101
|
+
async getRDSMonthlyCost(instanceClass, engine) {
|
|
102
|
+
if (this.useAccuratePricing && this.pricingService && engine) {
|
|
103
|
+
try {
|
|
104
|
+
return await this.pricingService.getRDSPrice(instanceClass, engine);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
// Fallback to estimate
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return exports.RDS_PRICING[instanceClass] || 100;
|
|
111
|
+
}
|
|
112
|
+
getS3MonthlyCost(sizeGB, storageClass = 'standard') {
|
|
113
|
+
const pricePerGB = exports.S3_PRICING[storageClass] || exports.S3_PRICING.standard;
|
|
114
|
+
return sizeGB * pricePerGB;
|
|
115
|
+
}
|
|
116
|
+
getELBMonthlyCost(type = 'alb') {
|
|
117
|
+
return exports.ELB_PRICING[type];
|
|
118
|
+
}
|
|
119
|
+
getEIPMonthlyCost() {
|
|
120
|
+
return exports.EIP_PRICING_HOURLY * 730; // ~$3.65
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
exports.CostEstimator = CostEstimator;
|
|
124
|
+
// Legacy exports for backwards compatibility
|
|
67
125
|
function getEC2MonthlyCost(instanceType) {
|
|
68
|
-
return exports.EC2_PRICING[instanceType] ||
|
|
126
|
+
return exports.EC2_PRICING[instanceType] || 50;
|
|
69
127
|
}
|
|
70
128
|
function getEBSMonthlyCost(sizeGB, volumeType) {
|
|
71
129
|
const pricePerGB = exports.EBS_PRICING[volumeType] || 0.08;
|
|
72
130
|
return sizeGB * pricePerGB;
|
|
73
131
|
}
|
|
74
132
|
function getRDSMonthlyCost(instanceClass) {
|
|
75
|
-
return exports.RDS_PRICING[instanceClass] ||
|
|
133
|
+
return exports.RDS_PRICING[instanceClass] || 100;
|
|
76
134
|
}
|
|
77
135
|
function getS3MonthlyCost(sizeGB, storageClass = 'standard') {
|
|
78
136
|
const pricePerGB = exports.S3_PRICING[storageClass] || exports.S3_PRICING.standard;
|
|
@@ -82,5 +140,5 @@ function getELBMonthlyCost(type = 'alb') {
|
|
|
82
140
|
return exports.ELB_PRICING[type];
|
|
83
141
|
}
|
|
84
142
|
function getEIPMonthlyCost() {
|
|
85
|
-
return exports.EIP_PRICING_HOURLY * 730;
|
|
143
|
+
return exports.EIP_PRICING_HOURLY * 730;
|
|
86
144
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare class PricingService {
|
|
2
|
+
private pricingClient;
|
|
3
|
+
private region;
|
|
4
|
+
constructor(region?: string);
|
|
5
|
+
/**
|
|
6
|
+
* Get EC2 instance on-demand pricing for the configured region
|
|
7
|
+
*/
|
|
8
|
+
getEC2Price(instanceType: string): Promise<number>;
|
|
9
|
+
/**
|
|
10
|
+
* Get EBS volume pricing per GB
|
|
11
|
+
*/
|
|
12
|
+
getEBSPrice(volumeType: string): Promise<number>;
|
|
13
|
+
/**
|
|
14
|
+
* Get RDS instance pricing
|
|
15
|
+
*/
|
|
16
|
+
getRDSPrice(instanceClass: string, engine?: string): Promise<number>;
|
|
17
|
+
/**
|
|
18
|
+
* Extract price from AWS Pricing API response
|
|
19
|
+
*/
|
|
20
|
+
private extractPriceFromResponse;
|
|
21
|
+
/**
|
|
22
|
+
* Convert AWS region code to location name used in Pricing API
|
|
23
|
+
*/
|
|
24
|
+
private getLocationName;
|
|
25
|
+
/**
|
|
26
|
+
* Normalize RDS engine name for Pricing API
|
|
27
|
+
*/
|
|
28
|
+
private normalizeEngine;
|
|
29
|
+
/**
|
|
30
|
+
* Fallback estimates when API calls fail (based on us-east-1)
|
|
31
|
+
*/
|
|
32
|
+
private getFallbackEC2Price;
|
|
33
|
+
private getFallbackEBSPrice;
|
|
34
|
+
private getFallbackRDSPrice;
|
|
35
|
+
}
|
|
36
|
+
export declare function getS3MonthlyCost(sizeGB: number, storageClass?: string): number;
|
|
37
|
+
export declare function getELBMonthlyCost(type?: 'alb' | 'nlb' | 'clb'): number;
|
|
38
|
+
export declare function getEIPMonthlyCost(): number;
|