cdk-cost-analyzer 0.1.36 → 0.1.37

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.
Files changed (89) hide show
  1. package/.cdk-cost-analyzer-cache/metadata.json +8 -8
  2. package/README.md +193 -3
  3. package/action.yml +50 -0
  4. package/dist/action/136.index.js +936 -0
  5. package/dist/action/360.index.js +93 -0
  6. package/dist/action/443.index.js +780 -0
  7. package/dist/action/566.index.js +387 -0
  8. package/dist/action/579.index.js +270 -0
  9. package/dist/action/605.index.js +234 -0
  10. package/dist/action/762.index.js +632 -0
  11. package/dist/action/869.index.js +531 -0
  12. package/dist/action/956.index.js +1072 -0
  13. package/dist/action/998.index.js +1418 -0
  14. package/dist/action/action/index.d.ts +7 -0
  15. package/dist/action/analysis/SingleTemplateAnalyzer.d.ts +23 -0
  16. package/dist/action/analysis/index.d.ts +1 -0
  17. package/dist/action/api/index.d.ts +35 -0
  18. package/dist/action/api/single-template-types.d.ts +83 -0
  19. package/dist/action/api/types.d.ts +15 -0
  20. package/dist/action/cli/index.d.ts +2 -0
  21. package/dist/action/config/ConfigManager.d.ts +40 -0
  22. package/dist/action/config/index.d.ts +2 -0
  23. package/dist/action/config/types.d.ts +153 -0
  24. package/dist/action/diff/DiffEngine.d.ts +7 -0
  25. package/dist/action/diff/index.d.ts +2 -0
  26. package/dist/action/diff/types.d.ts +20 -0
  27. package/dist/action/index.d.ts +8 -0
  28. package/dist/action/index.js +4 -0
  29. package/dist/action/integrations/GitHubIntegration.d.ts +43 -0
  30. package/dist/action/integrations/GitLabIntegration.d.ts +7 -0
  31. package/dist/action/integrations/index.d.ts +3 -0
  32. package/dist/action/integrations/types.d.ts +40 -0
  33. package/dist/action/parser/TemplateParser.d.ts +8 -0
  34. package/dist/action/parser/index.d.ts +2 -0
  35. package/dist/action/parser/types.d.ts +30 -0
  36. package/dist/action/pipeline/PipelineOrchestrator.d.ts +23 -0
  37. package/dist/action/pipeline/index.d.ts +2 -0
  38. package/dist/action/pipeline/types.d.ts +41 -0
  39. package/dist/action/pricing/CacheManager.d.ts +75 -0
  40. package/dist/action/pricing/PricingClient.d.ts +17 -0
  41. package/dist/action/pricing/PricingService.d.ts +16 -0
  42. package/dist/action/pricing/RegionMapper.d.ts +14 -0
  43. package/dist/action/pricing/calculators/ALBCalculator.d.ts +15 -0
  44. package/dist/action/pricing/calculators/APIGatewayCalculator.d.ts +9 -0
  45. package/dist/action/pricing/calculators/AutoScalingGroupCalculator.d.ts +9 -0
  46. package/dist/action/pricing/calculators/CloudFrontCalculator.d.ts +49 -0
  47. package/dist/action/pricing/calculators/DynamoDBCalculator.d.ts +12 -0
  48. package/dist/action/pricing/calculators/EC2Calculator.d.ts +6 -0
  49. package/dist/action/pricing/calculators/ECSCalculator.d.ts +8 -0
  50. package/dist/action/pricing/calculators/EFSCalculator.d.ts +19 -0
  51. package/dist/action/pricing/calculators/ElastiCacheCalculator.d.ts +7 -0
  52. package/dist/action/pricing/calculators/LambdaCalculator.d.ts +14 -0
  53. package/dist/action/pricing/calculators/LaunchTemplateCalculator.d.ts +35 -0
  54. package/dist/action/pricing/calculators/NLBCalculator.d.ts +15 -0
  55. package/dist/action/pricing/calculators/NatGatewayCalculator.d.ts +10 -0
  56. package/dist/action/pricing/calculators/RDSCalculator.d.ts +8 -0
  57. package/dist/action/pricing/calculators/S3Calculator.d.ts +7 -0
  58. package/dist/action/pricing/calculators/SNSCalculator.d.ts +54 -0
  59. package/dist/action/pricing/calculators/SQSCalculator.d.ts +16 -0
  60. package/dist/action/pricing/calculators/SecretsManagerCalculator.d.ts +21 -0
  61. package/dist/action/pricing/calculators/StepFunctionsCalculator.d.ts +23 -0
  62. package/dist/action/pricing/calculators/VPCEndpointCalculator.d.ts +10 -0
  63. package/dist/action/pricing/index.d.ts +16 -0
  64. package/dist/action/pricing/types.d.ts +54 -0
  65. package/dist/action/reporter/GitHubActionReporter.d.ts +42 -0
  66. package/dist/action/reporter/Reporter.d.ts +18 -0
  67. package/dist/action/reporter/SingleTemplateReporter.d.ts +31 -0
  68. package/dist/action/reporter/index.d.ts +4 -0
  69. package/dist/action/reporter/types.d.ts +72 -0
  70. package/dist/action/synthesis/SynthesisOrchestrator.d.ts +26 -0
  71. package/dist/action/synthesis/index.d.ts +2 -0
  72. package/dist/action/synthesis/types.d.ts +17 -0
  73. package/dist/action/threshold/ThresholdEnforcer.d.ts +29 -0
  74. package/dist/action/threshold/index.d.ts +2 -0
  75. package/dist/action/threshold/types.d.ts +15 -0
  76. package/dist/action/utils/Logger.d.ts +39 -0
  77. package/dist/cli/index.js +56 -1
  78. package/dist/integrations/GitHubIntegration.d.ts +43 -0
  79. package/dist/integrations/GitHubIntegration.js +217 -0
  80. package/dist/integrations/index.d.ts +1 -0
  81. package/dist/integrations/index.js +4 -2
  82. package/dist/integrations/types.d.ts +29 -0
  83. package/dist/integrations/types.js +11 -2
  84. package/dist/releasetag.txt +1 -1
  85. package/dist/reporter/GitHubActionReporter.d.ts +42 -0
  86. package/dist/reporter/GitHubActionReporter.js +161 -0
  87. package/dist/reporter/index.d.ts +1 -0
  88. package/dist/reporter/index.js +4 -2
  89. package/package.json +5 -1
@@ -2,35 +2,35 @@
2
2
  "entries": {
3
3
  "AmazonS3:US East (N. Virginia):storageClass:General Purpose|volumeType:Standard": {
4
4
  "price": 0.023,
5
- "timestamp": 1770993763154
5
+ "timestamp": 1771000028622
6
6
  },
7
7
  "AmazonDynamoDB:US East (N. Virginia):group:DDB-ReadUnits|productFamily:Amazon DynamoDB PayPerRequest Throughput": {
8
8
  "price": 0.023,
9
- "timestamp": 1770993763160
9
+ "timestamp": 1771000028634
10
10
  },
11
11
  "AmazonDynamoDB:US East (N. Virginia):group:DDB-WriteUnits|productFamily:Amazon DynamoDB PayPerRequest Throughput": {
12
12
  "price": 0.023,
13
- "timestamp": 1770993763160
13
+ "timestamp": 1771000028634
14
14
  },
15
15
  "AmazonEC2:US East (N. Virginia):capacitystatus:Used|instanceType:t3.micro|operatingSystem:Linux|preInstalledSw:NA|tenancy:Shared": {
16
16
  "price": 0.023,
17
- "timestamp": 1770993763175
17
+ "timestamp": 1771000028644
18
18
  },
19
19
  "AWSLambda:US East (N. Virginia):group:AWS-Lambda-Requests": {
20
20
  "price": 0.023,
21
- "timestamp": 1770993763183
21
+ "timestamp": 1771000028649
22
22
  },
23
23
  "AWSLambda:US East (N. Virginia):group:AWS-Lambda-Duration": {
24
24
  "price": 0.023,
25
- "timestamp": 1770993763183
25
+ "timestamp": 1771000028650
26
26
  },
27
27
  "AmazonS3:EU (Frankfurt):storageClass:General Purpose|volumeType:Standard": {
28
28
  "price": 0.023,
29
- "timestamp": 1770993771199
29
+ "timestamp": 1771000037494
30
30
  },
31
31
  "AmazonS3:invalid-region-123:storageClass:General Purpose|volumeType:Standard": {
32
32
  "price": 0.023,
33
- "timestamp": 1770993771251
33
+ "timestamp": 1771000037543
34
34
  }
35
35
  }
36
36
  }
package/README.md CHANGED
@@ -16,13 +16,14 @@ A TypeScript package that analyzes AWS CDK infrastructure changes and provides c
16
16
  - **Configuration Management**: Project-specific configuration for thresholds, usage assumptions, and exclusions
17
17
  - **Dual Interface**: Use as a CLI tool for quick analysis or import as a library for programmatic integration
18
18
  - **Clear Reporting**: Generate formatted cost reports in text, JSON, or Markdown formats
19
+ - **GitHub Integration**: Native GitHub Action and CLI support to post cost analysis to pull requests with trend indicators
19
20
  - **GitLab Integration**: Post cost analysis reports as comments on GitLab merge requests
20
21
  - **FinOps Awareness**: Help developers understand cost implications during the development cycle
21
22
 
22
23
  ## Use Cases
23
24
 
24
25
  - Analyze single CloudFormation templates for cost estimation
25
- - Analyze infrastructure changes in GitLab merge requests
26
+ - Analyze infrastructure changes in GitHub pull requests and GitLab merge requests
26
27
  - Estimate costs before deploying CDK applications
27
28
  - Enforce cost approval gates in CI/CD pipelines
28
29
  - Compare different infrastructure configurations
@@ -225,7 +226,164 @@ See the [CI/CD Integration Guide](docs/CI_CD.md) for complete documentation.
225
226
 
226
227
  ### GitHub Actions Integration
227
228
 
228
- Add to your `.github/workflows/ci.yml`:
229
+ #### Using the GitHub Action
230
+
231
+ The simplest way to integrate CDK Cost Analyzer into your GitHub workflow is using the official action:
232
+
233
+ ```yaml
234
+ name: Cost Analysis
235
+
236
+ on:
237
+ pull_request:
238
+ branches: [main]
239
+
240
+ permissions:
241
+ contents: read
242
+ pull-requests: write
243
+
244
+ jobs:
245
+ analyze-costs:
246
+ runs-on: ubuntu-latest
247
+ steps:
248
+ - uses: actions/checkout@v4
249
+
250
+ - uses: actions/setup-node@v4
251
+ with:
252
+ node-version: '20.x'
253
+ cache: 'npm'
254
+
255
+ - name: Install dependencies
256
+ run: npm ci
257
+
258
+ - name: Configure AWS credentials
259
+ uses: aws-actions/configure-aws-credentials@v4
260
+ with:
261
+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
262
+ aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
263
+ aws-region: us-east-1
264
+
265
+ - name: Run CDK Cost Analysis
266
+ uses: buildinginthecloud/cdk-cost-analyzer@v1
267
+ with:
268
+ path: './infrastructure'
269
+ github-token: ${{ secrets.GITHUB_TOKEN }}
270
+ aws-region: 'us-east-1'
271
+ config-path: '.cdk-cost-analyzer.yml'
272
+ comment-strategy: 'update'
273
+ ```
274
+
275
+ #### Action Inputs
276
+
277
+ | Input | Description | Required | Default |
278
+ |-------|-------------|----------|---------|
279
+ | `path` | Path to CDK app directory | No | `./` |
280
+ | `github-token` | GitHub token for API access | Yes | - |
281
+ | `aws-region` | AWS region for pricing data | No | `us-east-1` |
282
+ | `config-path` | Path to configuration file | No | - |
283
+ | `comment-strategy` | Comment update strategy: `new`, `update`, or `delete-and-new` | No | `update` |
284
+ | `debug` | Enable debug logging | No | `false` |
285
+
286
+ #### Action Outputs
287
+
288
+ | Output | Description |
289
+ |--------|-------------|
290
+ | `total-delta` | Total monthly cost delta |
291
+ | `currency` | Currency code (e.g., USD) |
292
+ | `added-count` | Number of added resources |
293
+ | `removed-count` | Number of removed resources |
294
+ | `modified-count` | Number of modified resources |
295
+ | `threshold-passed` | Whether the cost threshold check passed |
296
+ | `threshold-level` | Threshold level triggered (none, warning, or error) |
297
+
298
+ #### Comment Strategies
299
+
300
+ - **`new`**: Always create a new comment on each run
301
+ - **`update`** (default): Find and update existing cost analysis comment, or create new if not found
302
+ - **`delete-and-new`**: Delete existing comment and create a new one
303
+
304
+ #### Example PR Comment Output
305
+
306
+ The action posts a formatted comment to your pull request:
307
+
308
+ ```markdown
309
+ ## 💰 CDK Cost Analysis
310
+
311
+ **Monthly Cost Impact:** ↗️ +$245.60
312
+ **Percentage Change:** +15.3%
313
+
314
+ | Metric | Value |
315
+ |--------|-------|
316
+ | Base Monthly Cost | $1,605.40 |
317
+ | Target Monthly Cost | $1,851.00 |
318
+ | Cost Delta | +$245.60 |
319
+
320
+ ### ➕ Added Resources
321
+
322
+ | Logical ID | Type | Monthly Cost |
323
+ |------------|------|--------------|
324
+ | MyRDSInstance | `AWS::RDS::DBInstance` | $215.20 |
325
+ | MyEC2Instance | `AWS::EC2::Instance` | $30.40 |
326
+ | **Total Added** | | **$245.60** |
327
+
328
+ ---
329
+ *Generated by [cdk-cost-analyzer](https://github.com/buildinginthecloud/cdk-cost-analyzer)*
330
+ ```
331
+
332
+ #### Using CLI in GitHub Actions
333
+
334
+ You can also use the CLI directly with the `--post-to-github` flag:
335
+
336
+ ```yaml
337
+ name: Cost Analysis
338
+
339
+ on:
340
+ pull_request:
341
+ branches: [main]
342
+
343
+ permissions:
344
+ contents: read
345
+ pull-requests: write
346
+
347
+ jobs:
348
+ analyze-costs:
349
+ runs-on: ubuntu-latest
350
+ steps:
351
+ - uses: actions/checkout@v4
352
+
353
+ - uses: actions/setup-node@v4
354
+ with:
355
+ node-version: '20.x'
356
+ cache: 'npm'
357
+
358
+ - name: Install dependencies
359
+ run: npm ci
360
+
361
+ - name: Install CDK Cost Analyzer
362
+ run: npm install -g cdk-cost-analyzer
363
+
364
+ - name: Configure AWS credentials
365
+ uses: aws-actions/configure-aws-credentials@v4
366
+ with:
367
+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
368
+ aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
369
+ aws-region: us-east-1
370
+
371
+ - name: Run cost analysis
372
+ env:
373
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
374
+ run: |
375
+ cdk-cost-analyzer pipeline \
376
+ --synth \
377
+ --cdk-app-path ./infrastructure \
378
+ --region us-east-1 \
379
+ --config .cdk-cost-analyzer.yml \
380
+ --post-to-github \
381
+ --comment-strategy update
382
+ ```
383
+
384
+ #### Basic CI Workflow
385
+
386
+ For basic CI testing without cost analysis:
229
387
 
230
388
  ```yaml
231
389
  name: CI
@@ -331,6 +489,37 @@ cost-analysis:
331
489
  - merge_requests
332
490
  ```
333
491
 
492
+ ### GitHub Integration
493
+
494
+ Post cost analysis reports as comments on GitHub pull requests:
495
+
496
+ ```typescript
497
+ import { analyzeCosts, GitHubIntegration } from 'cdk-cost-analyzer';
498
+
499
+ // Analyze costs
500
+ const result = await analyzeCosts({
501
+ baseTemplate: baseTemplateContent,
502
+ targetTemplate: targetTemplateContent,
503
+ region: 'us-east-1',
504
+ format: 'markdown'
505
+ });
506
+
507
+ // Post to GitHub PR
508
+ const github = GitHubIntegration.fromEnvironment();
509
+ await github.postPRComment(
510
+ 'owner',
511
+ 'repo',
512
+ 123, // PR number
513
+ result.summary,
514
+ 'update' // comment strategy: 'new', 'update', or 'delete-and-new'
515
+ );
516
+ ```
517
+
518
+ Environment variables for GitHub integration:
519
+ - `GITHUB_TOKEN`: GitHub API token (required)
520
+ - `GITHUB_API_URL`: GitHub API URL (optional, defaults to `https://api.github.com`)
521
+ - `GITHUB_REPOSITORY`: Repository in `owner/repo` format (set automatically in GitHub Actions)
522
+
334
523
  ## Supported Resource Types
335
524
 
336
525
  ### Core Resources (Phase 1 & 2)
@@ -498,6 +687,7 @@ The tool handles errors gracefully:
498
687
  - **API failures**: Automatic retry with exponential backoff, fallback to cached data
499
688
  - **Unsupported resources**: Marked as "unknown cost", analysis continues
500
689
  - **GitLab API errors**: Descriptive error messages with HTTP status codes
690
+ - **GitHub API errors**: Descriptive error messages with HTTP status codes
501
691
 
502
692
  ## Development Roadmap
503
693
 
@@ -525,6 +715,7 @@ The tool handles errors gracefully:
525
715
  - **Additional Resource Calculators**: NAT Gateway, ALB, NLB, VPC Endpoints
526
716
  - **Enhanced CLI**: Pipeline command with synthesis and threshold support
527
717
  - **Comprehensive Documentation**: Configuration guide, GitLab CI/CD examples
718
+ - **GitHub Actions Integration**: Native action and CLI support for posting PR comments
528
719
 
529
720
  ### Phase 4 (Planned)
530
721
 
@@ -533,7 +724,6 @@ The tool handles errors gracefully:
533
724
  - Cost optimization recommendations
534
725
  - Support for Savings Plans and Reserved Instances
535
726
  - Additional resource types (CloudFront, ElastiCache, EKS)
536
- - GitHub Actions integration
537
727
  - Slack/Teams notifications
538
728
 
539
729
  ## Testing
package/action.yml ADDED
@@ -0,0 +1,50 @@
1
+ name: 'CDK Cost Analyzer'
2
+ description: 'Analyze AWS CDK infrastructure changes and post cost impact summaries to pull requests'
3
+ author: 'Building in the Cloud'
4
+ branding:
5
+ icon: 'dollar-sign'
6
+ color: 'green'
7
+
8
+ inputs:
9
+ path:
10
+ description: 'Path to CDK app directory'
11
+ required: false
12
+ default: './'
13
+ github-token:
14
+ description: 'GitHub token for API access (required for PR comments)'
15
+ required: true
16
+ aws-region:
17
+ description: 'AWS region for pricing data'
18
+ required: false
19
+ default: 'us-east-1'
20
+ config-path:
21
+ description: 'Path to cdk-cost-analyzer configuration file'
22
+ required: false
23
+ comment-strategy:
24
+ description: 'Comment update strategy: new, update, or delete-and-new'
25
+ required: false
26
+ default: 'update'
27
+ debug:
28
+ description: 'Enable debug logging'
29
+ required: false
30
+ default: 'false'
31
+
32
+ outputs:
33
+ total-delta:
34
+ description: 'Total monthly cost delta'
35
+ currency:
36
+ description: 'Currency code (e.g., USD)'
37
+ added-count:
38
+ description: 'Number of added resources'
39
+ removed-count:
40
+ description: 'Number of removed resources'
41
+ modified-count:
42
+ description: 'Number of modified resources'
43
+ threshold-passed:
44
+ description: 'Whether the cost threshold check passed'
45
+ threshold-level:
46
+ description: 'Threshold level triggered (none, warning, or error)'
47
+
48
+ runs:
49
+ using: 'node20'
50
+ main: 'dist/action/index.js'