cdk-cost-analyzer 0.1.41 → 0.1.43
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/.cdk-cost-analyzer-cache/metadata.json +8 -8
- package/dist/action/api/index.d.ts +1 -0
- package/dist/action/api/single-template-types.d.ts +4 -0
- package/dist/action/api/types.d.ts +3 -0
- package/dist/action/config/types.d.ts +2 -0
- package/dist/action/optimization/OptimizationEngine.d.ts +11 -0
- package/dist/action/optimization/analyzers/GravitonMigrationAnalyzer.d.ts +17 -0
- package/dist/action/optimization/analyzers/NATGatewayOptimizationAnalyzer.d.ts +13 -0
- package/dist/action/optimization/analyzers/ReservedInstanceAnalyzer.d.ts +13 -0
- package/dist/action/optimization/analyzers/RightSizingAnalyzer.d.ts +13 -0
- package/dist/action/optimization/analyzers/SavingsPlansAnalyzer.d.ts +11 -0
- package/dist/action/optimization/analyzers/SpotInstanceAnalyzer.d.ts +12 -0
- package/dist/action/optimization/analyzers/StorageOptimizationAnalyzer.d.ts +14 -0
- package/dist/action/optimization/defaults.d.ts +2 -0
- package/dist/action/optimization/index.d.ts +10 -0
- package/dist/action/optimization/types.d.ts +35 -0
- package/dist/action/reporter/RecommendationReporter.d.ts +3 -0
- package/dist/analysis/SingleTemplateAnalyzer.js +12 -1
- package/dist/api/index.d.ts +1 -0
- package/dist/api/index.js +2 -1
- package/dist/api/single-template-types.d.ts +4 -0
- package/dist/api/single-template-types.js +1 -1
- package/dist/api/types.d.ts +3 -0
- package/dist/api/types.js +1 -1
- package/dist/cli/index.js +13 -2
- package/dist/config/types.d.ts +2 -0
- package/dist/config/types.js +1 -1
- package/dist/optimization/OptimizationEngine.d.ts +11 -0
- package/dist/optimization/OptimizationEngine.js +51 -0
- package/dist/optimization/analyzers/GravitonMigrationAnalyzer.d.ts +17 -0
- package/dist/optimization/analyzers/GravitonMigrationAnalyzer.js +209 -0
- package/dist/optimization/analyzers/NATGatewayOptimizationAnalyzer.d.ts +13 -0
- package/dist/optimization/analyzers/NATGatewayOptimizationAnalyzer.js +142 -0
- package/dist/optimization/analyzers/ReservedInstanceAnalyzer.d.ts +13 -0
- package/dist/optimization/analyzers/ReservedInstanceAnalyzer.js +102 -0
- package/dist/optimization/analyzers/RightSizingAnalyzer.d.ts +13 -0
- package/dist/optimization/analyzers/RightSizingAnalyzer.js +109 -0
- package/dist/optimization/analyzers/SavingsPlansAnalyzer.d.ts +11 -0
- package/dist/optimization/analyzers/SavingsPlansAnalyzer.js +102 -0
- package/dist/optimization/analyzers/SpotInstanceAnalyzer.d.ts +12 -0
- package/dist/optimization/analyzers/SpotInstanceAnalyzer.js +113 -0
- package/dist/optimization/analyzers/StorageOptimizationAnalyzer.d.ts +14 -0
- package/dist/optimization/analyzers/StorageOptimizationAnalyzer.js +142 -0
- package/dist/optimization/defaults.d.ts +2 -0
- package/dist/optimization/defaults.js +22 -0
- package/dist/optimization/index.d.ts +10 -0
- package/dist/optimization/index.js +22 -0
- package/dist/optimization/types.d.ts +35 -0
- package/dist/optimization/types.js +3 -0
- package/dist/releasetag.txt +1 -1
- package/dist/reporter/RecommendationReporter.d.ts +3 -0
- package/dist/reporter/RecommendationReporter.js +133 -0
- package/dist/reporter/SingleTemplateReporter.js +11 -1
- package/docs/CALCULATORS.md +374 -8
- package/docs/README.md +3 -2
- package/docs/RECOMMENDATIONS.md +466 -0
- package/docs/SINGLE-TEMPLATE-ANALYSIS.md +59 -16
- package/docs/index.md +38 -8
- package/examples/recommendations-demo.json +74 -0
- package/package.json +1 -1
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
# Cost Optimization Recommendations
|
|
2
|
+
|
|
3
|
+
CDK Cost Analyzer includes an optimization engine that analyzes your CloudFormation templates and suggests cost-saving opportunities. The engine runs 7 specialized analyzers that cover compute, storage, networking, and purchasing strategies.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### CLI Usage
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
# Analyze a template with recommendations
|
|
11
|
+
cdk-cost-analyzer analyze template.json --recommendations
|
|
12
|
+
|
|
13
|
+
# Filter recommendations by minimum monthly savings
|
|
14
|
+
cdk-cost-analyzer analyze template.json --recommendations --min-savings 50
|
|
15
|
+
|
|
16
|
+
# Markdown output (for CI/CD comments)
|
|
17
|
+
cdk-cost-analyzer analyze template.json --recommendations --format markdown
|
|
18
|
+
|
|
19
|
+
# JSON output (for programmatic processing)
|
|
20
|
+
cdk-cost-analyzer analyze template.json --recommendations --format json
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### Programmatic Usage
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
import { analyzeSingleTemplate } from 'cdk-cost-analyzer';
|
|
27
|
+
|
|
28
|
+
const result = await analyzeSingleTemplate({
|
|
29
|
+
template: templateContent,
|
|
30
|
+
region: 'us-east-1',
|
|
31
|
+
config: {
|
|
32
|
+
recommendations: true,
|
|
33
|
+
minimumSavingsThreshold: 25, // Only show recommendations saving >= $25/month
|
|
34
|
+
},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Access recommendations
|
|
38
|
+
if (result.recommendations) {
|
|
39
|
+
console.log(`Total potential savings: $${result.recommendations.totalEstimatedMonthlySavings}/month`);
|
|
40
|
+
for (const rec of result.recommendations.recommendations) {
|
|
41
|
+
console.log(`- ${rec.title}: $${rec.estimatedMonthlySavings}/month`);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Analyzers
|
|
47
|
+
|
|
48
|
+
### Graviton Migration
|
|
49
|
+
|
|
50
|
+
**Category:** `graviton-migration`
|
|
51
|
+
|
|
52
|
+
Identifies x86 instances that can migrate to AWS Graviton processors for approximately 20% cost savings.
|
|
53
|
+
|
|
54
|
+
**Supported Resource Types:**
|
|
55
|
+
- AWS::EC2::Instance
|
|
56
|
+
- AWS::EC2::LaunchTemplate
|
|
57
|
+
- AWS::RDS::DBInstance
|
|
58
|
+
- AWS::RDS::DBCluster
|
|
59
|
+
- AWS::ElastiCache::CacheCluster
|
|
60
|
+
- AWS::ElastiCache::ReplicationGroup
|
|
61
|
+
|
|
62
|
+
**Instance Family Mappings:**
|
|
63
|
+
|
|
64
|
+
| x86 Family | Graviton Equivalent | Savings Estimate |
|
|
65
|
+
|------------|-------------------|-----------------|
|
|
66
|
+
| m5 | m7g | ~20% |
|
|
67
|
+
| c5 | c7g | ~20% |
|
|
68
|
+
| r5 | r7g | ~20% |
|
|
69
|
+
| t3 | t4g | ~20% |
|
|
70
|
+
|
|
71
|
+
**Example Recommendation:**
|
|
72
|
+
```
|
|
73
|
+
Migrate to Graviton Instances
|
|
74
|
+
Estimated Savings: $90.52/month (20%)
|
|
75
|
+
Affected Resources: WebServer, WorkerNode
|
|
76
|
+
Action Items:
|
|
77
|
+
1. Change instance type from m5.2xlarge to m7g.2xlarge
|
|
78
|
+
2. Test application compatibility with ARM64 architecture
|
|
79
|
+
Caveats:
|
|
80
|
+
- Requires ARM64-compatible AMIs and software
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### NAT Gateway Optimization
|
|
84
|
+
|
|
85
|
+
**Category:** `nat-gateway-optimization`
|
|
86
|
+
|
|
87
|
+
Identifies opportunities to reduce NAT Gateway costs through replacement, VPC endpoints, or consolidation.
|
|
88
|
+
|
|
89
|
+
**Supported Resource Types:**
|
|
90
|
+
- AWS::EC2::NatGateway
|
|
91
|
+
|
|
92
|
+
**Recommendation Types:**
|
|
93
|
+
|
|
94
|
+
1. **NAT Instance Replacement** - Replace NAT Gateways with t3.nano NAT instances in dev/test environments
|
|
95
|
+
2. **VPC Gateway Endpoints** - Add free Gateway Endpoints for S3 and DynamoDB to reduce data processing charges
|
|
96
|
+
3. **NAT Gateway Consolidation** - Consolidate multiple NAT Gateways when template contains 2 or more
|
|
97
|
+
|
|
98
|
+
**Example Recommendation:**
|
|
99
|
+
```
|
|
100
|
+
Use VPC Gateway Endpoints for S3/DynamoDB
|
|
101
|
+
Estimated Savings: $20.00/month
|
|
102
|
+
Affected Resources: NATGateway1, NATGateway2
|
|
103
|
+
Action Items:
|
|
104
|
+
1. Add VPC Gateway Endpoint for S3 (free)
|
|
105
|
+
2. Add VPC Gateway Endpoint for DynamoDB (free)
|
|
106
|
+
3. Update route tables to use endpoints
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Storage Optimization
|
|
110
|
+
|
|
111
|
+
**Category:** `storage-optimization`
|
|
112
|
+
|
|
113
|
+
Identifies storage cost savings through volume type migration and S3 lifecycle management.
|
|
114
|
+
|
|
115
|
+
**Supported Resource Types:**
|
|
116
|
+
- AWS::EC2::Volume
|
|
117
|
+
- AWS::EC2::LaunchTemplate (block device mappings)
|
|
118
|
+
- AWS::S3::Bucket
|
|
119
|
+
|
|
120
|
+
**Recommendation Types:**
|
|
121
|
+
|
|
122
|
+
1. **EBS gp2 to gp3 Migration** - gp3 volumes are ~20% cheaper than gp2 with equivalent or better performance
|
|
123
|
+
2. **S3 Intelligent-Tiering** - Automatically moves objects between access tiers based on usage patterns
|
|
124
|
+
3. **S3 Lifecycle Rules** - Archive or expire objects to reduce storage costs
|
|
125
|
+
|
|
126
|
+
**Example Recommendation:**
|
|
127
|
+
```
|
|
128
|
+
Migrate EBS Volumes from gp2 to gp3
|
|
129
|
+
Estimated Savings: $10.00/month (20%)
|
|
130
|
+
Affected Resources: DataVolume
|
|
131
|
+
Action Items:
|
|
132
|
+
1. Change VolumeType from gp2 to gp3
|
|
133
|
+
2. Verify IOPS and throughput requirements
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Reserved Instances
|
|
137
|
+
|
|
138
|
+
**Category:** `reserved-instance`
|
|
139
|
+
|
|
140
|
+
Recommends Reserved Instance purchases for resources with predictable usage and costs exceeding $50/month.
|
|
141
|
+
|
|
142
|
+
**Supported Resource Types:**
|
|
143
|
+
- AWS::EC2::Instance
|
|
144
|
+
- AWS::RDS::DBInstance
|
|
145
|
+
- AWS::RDS::DBCluster
|
|
146
|
+
- AWS::ElastiCache::CacheCluster
|
|
147
|
+
- AWS::ElastiCache::ReplicationGroup
|
|
148
|
+
- AWS::Redshift::Cluster
|
|
149
|
+
- AWS::OpenSearchService::Domain
|
|
150
|
+
- AWS::Elasticsearch::Domain
|
|
151
|
+
|
|
152
|
+
**Pricing Model:**
|
|
153
|
+
- 1-year, No Upfront commitment
|
|
154
|
+
- Estimated discount: ~30%
|
|
155
|
+
- Only triggers for individual resources costing >= $50/month
|
|
156
|
+
|
|
157
|
+
**Example Recommendation:**
|
|
158
|
+
```
|
|
159
|
+
Consider Reserved Instances for EC2
|
|
160
|
+
Estimated Savings: $135.78/month (30%)
|
|
161
|
+
Affected Resources: WebServer
|
|
162
|
+
Action Items:
|
|
163
|
+
1. Review instance utilization over past 30 days
|
|
164
|
+
2. Purchase 1-year No Upfront Reserved Instance
|
|
165
|
+
Caveats:
|
|
166
|
+
- Requires 1-year commitment
|
|
167
|
+
- Instance type and region locked
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### Savings Plans
|
|
171
|
+
|
|
172
|
+
**Category:** `savings-plan`
|
|
173
|
+
|
|
174
|
+
Recommends Savings Plans for aggregate compute spend exceeding $100/month.
|
|
175
|
+
|
|
176
|
+
**Supported Resource Types:**
|
|
177
|
+
- AWS::EC2::Instance
|
|
178
|
+
- AWS::EC2::LaunchTemplate
|
|
179
|
+
- AWS::AutoScaling::AutoScalingGroup
|
|
180
|
+
- AWS::ECS::Service
|
|
181
|
+
- AWS::Lambda::Function
|
|
182
|
+
|
|
183
|
+
**Plan Types:**
|
|
184
|
+
|
|
185
|
+
| Plan Type | Discount | Scope |
|
|
186
|
+
|-----------|----------|-------|
|
|
187
|
+
| Compute Savings Plan | ~30% | EC2, Fargate, Lambda |
|
|
188
|
+
| EC2 Instance Savings Plan | ~35% | EC2 only |
|
|
189
|
+
|
|
190
|
+
**Trigger Condition:** Total compute cost across all resources must exceed $100/month.
|
|
191
|
+
|
|
192
|
+
**Example Recommendation:**
|
|
193
|
+
```
|
|
194
|
+
Purchase Compute Savings Plan
|
|
195
|
+
Estimated Savings: $300.00/month (30%)
|
|
196
|
+
Affected Resources: WebServer, WorkerASG, ApiFunction
|
|
197
|
+
Action Items:
|
|
198
|
+
1. Review 30-day compute usage in AWS Cost Explorer
|
|
199
|
+
2. Purchase Compute Savings Plan via AWS Console
|
|
200
|
+
Caveats:
|
|
201
|
+
- 1-year or 3-year commitment required
|
|
202
|
+
- Applies to EC2, Fargate, and Lambda
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
### Right-Sizing
|
|
206
|
+
|
|
207
|
+
**Category:** `right-sizing`
|
|
208
|
+
|
|
209
|
+
Identifies oversized instances (2xlarge and larger) that may benefit from downsizing.
|
|
210
|
+
|
|
211
|
+
**Supported Resource Types:**
|
|
212
|
+
- AWS::EC2::Instance
|
|
213
|
+
- AWS::RDS::DBInstance
|
|
214
|
+
- AWS::ElastiCache::CacheCluster
|
|
215
|
+
|
|
216
|
+
**Trigger Condition:** Instance size must be 2xlarge or larger.
|
|
217
|
+
|
|
218
|
+
**Savings Estimate:** ~50% per size reduction (e.g., 2xlarge to xlarge).
|
|
219
|
+
|
|
220
|
+
**Example Recommendation:**
|
|
221
|
+
```
|
|
222
|
+
Right-size EC2 Instance: WebServer
|
|
223
|
+
Estimated Savings: $226.30/month (50%)
|
|
224
|
+
Affected Resources: WebServer
|
|
225
|
+
Action Items:
|
|
226
|
+
1. Review CloudWatch CPU and memory utilization metrics
|
|
227
|
+
2. Consider downsizing from m5.2xlarge to m5.xlarge
|
|
228
|
+
3. Test with reduced capacity before committing
|
|
229
|
+
Caveats:
|
|
230
|
+
- Verify application performance requirements
|
|
231
|
+
- Monitor after resize for capacity issues
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
### Spot Instances
|
|
235
|
+
|
|
236
|
+
**Category:** `spot-instance`
|
|
237
|
+
|
|
238
|
+
Identifies workloads suitable for Spot Instance pricing.
|
|
239
|
+
|
|
240
|
+
**Supported Resource Types:**
|
|
241
|
+
- AWS::AutoScaling::AutoScalingGroup (checks for MixedInstancesPolicy)
|
|
242
|
+
- AWS::ECS::Service (checks for CapacityProviderStrategy)
|
|
243
|
+
|
|
244
|
+
**Recommendation Types:**
|
|
245
|
+
|
|
246
|
+
1. **ASG Spot Instances** - Use Mixed Instances Policy with 50% Spot capacity (~30% savings)
|
|
247
|
+
2. **Fargate Spot** - Use Fargate Spot capacity provider for ECS services (~35% savings)
|
|
248
|
+
|
|
249
|
+
**Example Recommendation:**
|
|
250
|
+
```
|
|
251
|
+
Use Spot Instances in Auto Scaling Group
|
|
252
|
+
Estimated Savings: $50.00/month (30%)
|
|
253
|
+
Affected Resources: WorkerASG
|
|
254
|
+
Action Items:
|
|
255
|
+
1. Add MixedInstancesPolicy to ASG
|
|
256
|
+
2. Set OnDemandPercentageAboveBaseCapacity to 50%
|
|
257
|
+
3. Diversify instance types for better Spot availability
|
|
258
|
+
Caveats:
|
|
259
|
+
- Spot Instances can be interrupted with 2 minutes notice
|
|
260
|
+
- Not suitable for stateful workloads
|
|
261
|
+
```
|
|
262
|
+
|
|
263
|
+
## Output Formats
|
|
264
|
+
|
|
265
|
+
### Text Format
|
|
266
|
+
|
|
267
|
+
Terminal-friendly output with priority indicators:
|
|
268
|
+
|
|
269
|
+
```
|
|
270
|
+
================================================================================
|
|
271
|
+
Cost Optimization Recommendations
|
|
272
|
+
================================================================================
|
|
273
|
+
|
|
274
|
+
Total Potential Savings: $1,130.96/month ($13,571.52/year)
|
|
275
|
+
Recommendations: 16
|
|
276
|
+
|
|
277
|
+
[!!!] 1. Right-size EC2 Instance: WebServer [Right Sizing]
|
|
278
|
+
Savings: $226.30/month (50%)
|
|
279
|
+
This is a test recommendation.
|
|
280
|
+
Affected: WebServer
|
|
281
|
+
Actions:
|
|
282
|
+
- Review CloudWatch CPU and memory utilization
|
|
283
|
+
- Consider downsizing from m5.2xlarge to m5.xlarge
|
|
284
|
+
Caveats:
|
|
285
|
+
- Verify application performance requirements
|
|
286
|
+
|
|
287
|
+
[!!] 2. Migrate to Graviton Instances [Graviton Migration]
|
|
288
|
+
Savings: $90.52/month (20%)
|
|
289
|
+
...
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
Priority indicators:
|
|
293
|
+
- `[!!!]` - High priority
|
|
294
|
+
- `[!!]` - Medium priority
|
|
295
|
+
- `[!]` - Low priority
|
|
296
|
+
|
|
297
|
+
### Markdown Format
|
|
298
|
+
|
|
299
|
+
GitHub/GitLab-friendly output with summary table and collapsible details:
|
|
300
|
+
|
|
301
|
+
```markdown
|
|
302
|
+
## Cost Optimization Recommendations
|
|
303
|
+
|
|
304
|
+
**Total Potential Savings:** $1,130.96/month ($13,571.52/year)
|
|
305
|
+
|
|
306
|
+
| # | Priority | Recommendation | Est. Savings |
|
|
307
|
+
|---|----------|---------------|-------------|
|
|
308
|
+
| 1 | high | Right-size EC2 Instance | $226.30/mo |
|
|
309
|
+
| 2 | medium | Migrate to Graviton | $90.52/mo |
|
|
310
|
+
|
|
311
|
+
<details>
|
|
312
|
+
<summary>View detailed recommendations</summary>
|
|
313
|
+
|
|
314
|
+
### 1. Right-size EC2 Instance: WebServer
|
|
315
|
+
**Priority:** high | **Category:** Right Sizing
|
|
316
|
+
**Estimated Savings:** $226.30/month (50%)
|
|
317
|
+
|
|
318
|
+
**Affected Resources:** `WebServer`
|
|
319
|
+
|
|
320
|
+
**Action Items:**
|
|
321
|
+
- [ ] Review CloudWatch CPU and memory utilization
|
|
322
|
+
- [ ] Consider downsizing from m5.2xlarge to m5.xlarge
|
|
323
|
+
|
|
324
|
+
> **Caveats:** Verify application performance requirements
|
|
325
|
+
</details>
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
### JSON Format
|
|
329
|
+
|
|
330
|
+
When using `--format json`, recommendations are output as structured data:
|
|
331
|
+
|
|
332
|
+
```json
|
|
333
|
+
{
|
|
334
|
+
"recommendations": {
|
|
335
|
+
"recommendations": [
|
|
336
|
+
{
|
|
337
|
+
"id": "graviton-ec2-WebServer",
|
|
338
|
+
"title": "Migrate to Graviton Instances",
|
|
339
|
+
"description": "...",
|
|
340
|
+
"category": "graviton-migration",
|
|
341
|
+
"priority": "medium",
|
|
342
|
+
"estimatedMonthlySavings": 90.52,
|
|
343
|
+
"estimatedSavingsPercent": 20,
|
|
344
|
+
"affectedResources": ["WebServer"],
|
|
345
|
+
"actionItems": ["Change instance type from m5.2xlarge to m7g.2xlarge"],
|
|
346
|
+
"caveats": ["Requires ARM64-compatible AMIs"]
|
|
347
|
+
}
|
|
348
|
+
],
|
|
349
|
+
"totalEstimatedMonthlySavings": 1130.96,
|
|
350
|
+
"currency": "USD",
|
|
351
|
+
"analyzedResourceCount": 10,
|
|
352
|
+
"analyzedAt": "2026-03-10T12:00:00.000Z"
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
## Configuration
|
|
358
|
+
|
|
359
|
+
### Minimum Savings Threshold
|
|
360
|
+
|
|
361
|
+
Filter out low-value recommendations:
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
# CLI: only show recommendations saving >= $50/month
|
|
365
|
+
cdk-cost-analyzer analyze template.json --recommendations --min-savings 50
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
```typescript
|
|
369
|
+
// API: minimum savings threshold
|
|
370
|
+
const result = await analyzeSingleTemplate({
|
|
371
|
+
template: templateContent,
|
|
372
|
+
config: {
|
|
373
|
+
recommendations: true,
|
|
374
|
+
minimumSavingsThreshold: 50,
|
|
375
|
+
},
|
|
376
|
+
});
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
### Category Filtering (API)
|
|
380
|
+
|
|
381
|
+
Enable or disable specific analyzer categories programmatically:
|
|
382
|
+
|
|
383
|
+
```typescript
|
|
384
|
+
import { OptimizationEngine, createDefaultAnalyzers } from 'cdk-cost-analyzer';
|
|
385
|
+
|
|
386
|
+
const engine = new OptimizationEngine(createDefaultAnalyzers(), {
|
|
387
|
+
enabledCategories: ['graviton-migration', 'storage-optimization'],
|
|
388
|
+
// or
|
|
389
|
+
disabledCategories: ['spot-instance'],
|
|
390
|
+
minimumSavingsThreshold: 25,
|
|
391
|
+
});
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Available categories:
|
|
395
|
+
- `graviton-migration`
|
|
396
|
+
- `nat-gateway-optimization`
|
|
397
|
+
- `storage-optimization`
|
|
398
|
+
- `reserved-instance`
|
|
399
|
+
- `savings-plan`
|
|
400
|
+
- `right-sizing`
|
|
401
|
+
- `spot-instance`
|
|
402
|
+
|
|
403
|
+
## Recommendation Priority Levels
|
|
404
|
+
|
|
405
|
+
| Priority | Criteria | Action |
|
|
406
|
+
|----------|----------|--------|
|
|
407
|
+
| High | Large savings, low risk, easy to implement | Implement immediately |
|
|
408
|
+
| Medium | Moderate savings or moderate effort | Plan for next sprint |
|
|
409
|
+
| Low | Small savings or significant caveats | Evaluate when convenient |
|
|
410
|
+
|
|
411
|
+
## Demo Template
|
|
412
|
+
|
|
413
|
+
A demo template is included for testing recommendations:
|
|
414
|
+
|
|
415
|
+
```bash
|
|
416
|
+
cdk-cost-analyzer analyze examples/recommendations-demo.json --recommendations
|
|
417
|
+
```
|
|
418
|
+
|
|
419
|
+
This template contains resources that trigger all 7 analyzer categories:
|
|
420
|
+
- m5.2xlarge EC2 instance (Graviton, right-sizing, Reserved Instance)
|
|
421
|
+
- db.r5.xlarge RDS instance (Graviton, Reserved Instance)
|
|
422
|
+
- cache.m5.large ElastiCache cluster (Graviton, Reserved Instance)
|
|
423
|
+
- 500 GB gp2 EBS volume (storage optimization)
|
|
424
|
+
- S3 bucket without lifecycle rules (storage optimization)
|
|
425
|
+
- 2 NAT Gateways (NAT optimization, consolidation)
|
|
426
|
+
- Auto Scaling Group (Spot instances, Savings Plans)
|
|
427
|
+
- Lambda function (Savings Plans)
|
|
428
|
+
- DynamoDB table (on-demand)
|
|
429
|
+
|
|
430
|
+
## Architecture
|
|
431
|
+
|
|
432
|
+
The optimization engine follows a pluggable analyzer pattern:
|
|
433
|
+
|
|
434
|
+
```
|
|
435
|
+
OptimizationEngine
|
|
436
|
+
├── GravitonMigrationAnalyzer
|
|
437
|
+
├── NATGatewayOptimizationAnalyzer
|
|
438
|
+
├── StorageOptimizationAnalyzer
|
|
439
|
+
├── ReservedInstanceAnalyzer
|
|
440
|
+
├── SavingsPlansAnalyzer
|
|
441
|
+
├── RightSizingAnalyzer
|
|
442
|
+
└── SpotInstanceAnalyzer
|
|
443
|
+
```
|
|
444
|
+
|
|
445
|
+
Each analyzer implements the `OptimizationAnalyzer` interface:
|
|
446
|
+
|
|
447
|
+
```typescript
|
|
448
|
+
interface OptimizationAnalyzer {
|
|
449
|
+
readonly category: OptimizationCategory;
|
|
450
|
+
readonly name: string;
|
|
451
|
+
isApplicable(resources: ResourceWithId[]): boolean;
|
|
452
|
+
analyze(
|
|
453
|
+
resources: ResourceWithId[],
|
|
454
|
+
resourceCosts: ResourceCost[],
|
|
455
|
+
region: string,
|
|
456
|
+
): Promise<Recommendation[]>;
|
|
457
|
+
}
|
|
458
|
+
```
|
|
459
|
+
|
|
460
|
+
Analyzers receive the full resource list and cost data, enabling cross-resource analysis (e.g., Savings Plans aggregating costs across EC2 + Lambda + ECS).
|
|
461
|
+
|
|
462
|
+
## Further Reading
|
|
463
|
+
|
|
464
|
+
- [Single Template Analysis](SINGLE-TEMPLATE-ANALYSIS.md) - CLI reference for the analyze command
|
|
465
|
+
- [Calculator Reference](CALCULATORS.md) - Cost calculation methods for each resource type
|
|
466
|
+
- [Configuration Guide](CONFIGURATION.md) - Project-wide configuration options
|
|
@@ -24,6 +24,22 @@ cdk-cost-analyzer analyze template.json --format markdown # Documentation-frien
|
|
|
24
24
|
cdk-cost-analyzer analyze template.json --debug
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
### Cost Optimization Recommendations
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Include cost optimization recommendations in the output
|
|
31
|
+
cdk-cost-analyzer analyze template.json --recommendations
|
|
32
|
+
|
|
33
|
+
# Filter recommendations by minimum monthly savings (USD)
|
|
34
|
+
cdk-cost-analyzer analyze template.json --recommendations --min-savings 50
|
|
35
|
+
|
|
36
|
+
# Combine with output formats
|
|
37
|
+
cdk-cost-analyzer analyze template.json --recommendations --format markdown
|
|
38
|
+
cdk-cost-analyzer analyze template.json --recommendations --format json
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
See [RECOMMENDATIONS.md](RECOMMENDATIONS.md) for detailed documentation on the optimization engine and all 7 analyzer categories.
|
|
42
|
+
|
|
27
43
|
### With Configuration
|
|
28
44
|
|
|
29
45
|
```bash
|
|
@@ -68,6 +84,30 @@ console.log(result.summary);
|
|
|
68
84
|
console.log(`Total cost: $${result.totalMonthlyCost.toFixed(2)}`);
|
|
69
85
|
```
|
|
70
86
|
|
|
87
|
+
### With Recommendations
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
const result = await analyzeSingleTemplate({
|
|
91
|
+
template: templateContent,
|
|
92
|
+
region: 'us-east-1',
|
|
93
|
+
config: {
|
|
94
|
+
recommendations: true,
|
|
95
|
+
minimumSavingsThreshold: 25,
|
|
96
|
+
},
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// Recommendations are included in result.summary for text/markdown formats
|
|
100
|
+
console.log(result.summary);
|
|
101
|
+
|
|
102
|
+
// Access structured recommendation data
|
|
103
|
+
if (result.recommendations) {
|
|
104
|
+
console.log(`Potential savings: $${result.recommendations.totalEstimatedMonthlySavings}/month`);
|
|
105
|
+
for (const rec of result.recommendations.recommendations) {
|
|
106
|
+
console.log(`- [${rec.priority}] ${rec.title}: $${rec.estimatedMonthlySavings}/month`);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
```
|
|
110
|
+
|
|
71
111
|
### With Configuration
|
|
72
112
|
|
|
73
113
|
```typescript
|
|
@@ -261,22 +301,25 @@ Error: AWS credentials not configured. Please set AWS credentials using one of:
|
|
|
261
301
|
|
|
262
302
|
## Supported Resource Types
|
|
263
303
|
|
|
264
|
-
The analyzer supports
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
304
|
+
The analyzer supports 25+ AWS resource types including:
|
|
305
|
+
|
|
306
|
+
**Compute:** EC2 Instances, Launch Templates, Auto Scaling Groups, EKS Clusters, ECS Services, Lambda Functions
|
|
307
|
+
|
|
308
|
+
**Database:** RDS Instances, Aurora Serverless (v1/v2), DynamoDB Tables, ElastiCache Clusters
|
|
309
|
+
|
|
310
|
+
**Storage:** S3 Buckets, EFS File Systems, EBS Volumes (via Launch Templates)
|
|
311
|
+
|
|
312
|
+
**Networking:** NAT Gateways, ALB, NLB, VPC Endpoints, Transit Gateways, Route 53 (Hosted Zones, Health Checks, Records)
|
|
313
|
+
|
|
314
|
+
**API and Content Delivery:** API Gateway (REST, HTTP, WebSocket), CloudFront Distributions
|
|
315
|
+
|
|
316
|
+
**Messaging:** SQS Queues, SNS Topics
|
|
317
|
+
|
|
318
|
+
**Analytics:** Kinesis Data Streams, Kinesis Firehose, Kinesis Analytics
|
|
319
|
+
|
|
320
|
+
**Other:** Step Functions, Secrets Manager
|
|
321
|
+
|
|
322
|
+
See [CALCULATORS.md](CALCULATORS.md) for complete list and calculation details.
|
|
280
323
|
|
|
281
324
|
## Usage Assumptions
|
|
282
325
|
|
package/docs/index.md
CHANGED
|
@@ -16,13 +16,14 @@ A TypeScript package that analyzes AWS CDK infrastructure changes and provides c
|
|
|
16
16
|
|
|
17
17
|
- **Single Template Analysis** - Analyze individual CloudFormation templates for estimated monthly costs without comparison
|
|
18
18
|
- **Template Comparison** - Parse and diff CloudFormation templates (JSON/YAML) to identify added, removed, and modified resources
|
|
19
|
-
- **Cost Estimation** - Calculate monthly costs for AWS
|
|
19
|
+
- **Cost Estimation** - Calculate monthly costs for 25+ AWS resource types using real-time AWS Pricing API data
|
|
20
|
+
- **Cost Optimization Recommendations** - Get actionable suggestions for Graviton migration, right-sizing, Reserved Instances, Savings Plans, storage optimization, NAT Gateway optimization, and Spot Instances
|
|
20
21
|
- **Automatic CDK Synthesis** - Optionally synthesize CDK applications in CI/CD pipelines
|
|
21
22
|
- **Cost Threshold Enforcement** - Fail pipelines when cost increases exceed configured thresholds
|
|
22
23
|
- **Configuration Management** - Project-specific configuration for thresholds, usage assumptions, and exclusions
|
|
23
24
|
- **Dual Interface** - Use as a CLI tool for quick analysis or import as a library for programmatic integration
|
|
24
25
|
- **Clear Reporting** - Generate formatted cost reports in text, JSON, or Markdown formats
|
|
25
|
-
- **
|
|
26
|
+
- **CI/CD Integration** - Post cost analysis reports as comments on GitHub pull requests and GitLab merge requests
|
|
26
27
|
- **FinOps Awareness** - Help developers understand cost implications during the development cycle
|
|
27
28
|
|
|
28
29
|
## Quick Start
|
|
@@ -75,6 +76,9 @@ aws configure
|
|
|
75
76
|
# Analyze a single CloudFormation template
|
|
76
77
|
cdk-cost-analyzer analyze template.json --region us-east-1
|
|
77
78
|
|
|
79
|
+
# Include cost optimization recommendations
|
|
80
|
+
cdk-cost-analyzer analyze template.json --recommendations --min-savings 50
|
|
81
|
+
|
|
78
82
|
# Compare two CloudFormation templates
|
|
79
83
|
cdk-cost-analyzer compare base.json target.json --region eu-central-1
|
|
80
84
|
|
|
@@ -111,6 +115,7 @@ console.log(`Total monthly cost: ${result.totalMonthlyCost} ${result.currency}`)
|
|
|
111
115
|
### Reference
|
|
112
116
|
|
|
113
117
|
- [Resource Calculator Reference](CALCULATORS.md) - Detailed cost calculation methods and assumptions
|
|
118
|
+
- [Cost Optimization Recommendations](RECOMMENDATIONS.md) - Actionable cost-saving suggestions
|
|
114
119
|
- [Single Template Analysis](SINGLE-TEMPLATE-ANALYSIS.md) - Analyze individual templates without comparison
|
|
115
120
|
- [NAT Gateway Testing](NAT_GATEWAY_TESTING.md) - Testing and debugging NAT Gateway pricing
|
|
116
121
|
|
|
@@ -122,26 +127,51 @@ console.log(`Total monthly cost: ${result.totalMonthlyCost} ${result.currency}`)
|
|
|
122
127
|
|
|
123
128
|
## Supported Resource Types
|
|
124
129
|
|
|
125
|
-
### Compute
|
|
130
|
+
### Compute
|
|
126
131
|
- AWS::EC2::Instance
|
|
127
|
-
- AWS::
|
|
132
|
+
- AWS::EC2::LaunchTemplate
|
|
133
|
+
- AWS::AutoScaling::AutoScalingGroup
|
|
134
|
+
- AWS::EKS::Cluster
|
|
135
|
+
- AWS::ECS::Service
|
|
128
136
|
- AWS::Lambda::Function
|
|
137
|
+
|
|
138
|
+
### Database
|
|
129
139
|
- AWS::RDS::DBInstance
|
|
140
|
+
- AWS::RDS::DBCluster (Aurora Serverless v1/v2)
|
|
130
141
|
- AWS::DynamoDB::Table
|
|
131
|
-
- AWS::
|
|
142
|
+
- AWS::ElastiCache::CacheCluster
|
|
143
|
+
|
|
144
|
+
### Storage
|
|
145
|
+
- AWS::S3::Bucket
|
|
146
|
+
- AWS::EFS::FileSystem
|
|
132
147
|
|
|
133
148
|
### Networking
|
|
134
149
|
- AWS::EC2::NatGateway
|
|
135
150
|
- AWS::ElasticLoadBalancingV2::LoadBalancer (ALB & NLB)
|
|
136
151
|
- AWS::EC2::VPCEndpoint
|
|
152
|
+
- AWS::EC2::TransitGateway
|
|
153
|
+
- AWS::EC2::TransitGatewayAttachment
|
|
154
|
+
- AWS::Route53::HostedZone
|
|
155
|
+
- AWS::Route53::HealthCheck
|
|
156
|
+
- AWS::Route53::RecordSet
|
|
137
157
|
|
|
138
|
-
### API
|
|
158
|
+
### API and Content Delivery
|
|
139
159
|
- AWS::ApiGateway::RestApi
|
|
140
160
|
- AWS::ApiGatewayV2::Api (HTTP & WebSocket)
|
|
141
161
|
- AWS::CloudFront::Distribution
|
|
142
162
|
|
|
143
|
-
###
|
|
144
|
-
- AWS::
|
|
163
|
+
### Messaging
|
|
164
|
+
- AWS::SQS::Queue
|
|
165
|
+
- AWS::SNS::Topic
|
|
166
|
+
|
|
167
|
+
### Analytics
|
|
168
|
+
- AWS::Kinesis::Stream
|
|
169
|
+
- AWS::KinesisFirehose::DeliveryStream
|
|
170
|
+
- AWS::KinesisAnalyticsV2::Application
|
|
171
|
+
|
|
172
|
+
### Other
|
|
173
|
+
- AWS::StepFunctions::StateMachine
|
|
174
|
+
- AWS::SecretsManager::Secret
|
|
145
175
|
|
|
146
176
|
See the [Calculator Reference](CALCULATORS.md) for complete details on cost calculation methods and assumptions.
|
|
147
177
|
|