cdk-cost-analyzer 0.1.1

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 (228) hide show
  1. package/.cdk-cost-analyzer-cache/metadata.json +12 -0
  2. package/.gitlab-ci.yml +214 -0
  3. package/.husky/pre-commit +12 -0
  4. package/.kiro/hooks/accessibility-audit.kiro.hook +18 -0
  5. package/.kiro/hooks/api-schema-validation.kiro.hook +21 -0
  6. package/.kiro/hooks/auto-test-on-save.kiro.hook +19 -0
  7. package/.kiro/hooks/cdk-synth-on-change.kiro.hook +20 -0
  8. package/.kiro/hooks/code-coverage-check.kiro.hook +14 -0
  9. package/.kiro/hooks/commit-message-helper.kiro.hook +14 -0
  10. package/.kiro/hooks/dependency-update-check.kiro.hook +14 -0
  11. package/.kiro/hooks/env-file-validation.kiro.hook +18 -0
  12. package/.kiro/hooks/lint-and-format-on-save.kiro.hook +21 -0
  13. package/.kiro/hooks/mcp-config-validation.kiro.hook +17 -0
  14. package/.kiro/hooks/mcp-server-test.kiro.hook +14 -0
  15. package/.kiro/hooks/performance-analysis.kiro.hook +14 -0
  16. package/.kiro/hooks/readme-spell-check.kiro.hook +14 -0
  17. package/.kiro/hooks/security-scan-on-dependency-change.kiro.hook +21 -0
  18. package/.kiro/hooks/translation-update.kiro.hook +18 -0
  19. package/.kiro/hooks/update-documentation.kiro.hook +18 -0
  20. package/.kiro/settings/mcp.json +20 -0
  21. package/.kiro/specs/cdk-cost-analyzer/design.md +620 -0
  22. package/.kiro/specs/cdk-cost-analyzer/requirements.md +183 -0
  23. package/.kiro/specs/cdk-cost-analyzer/tasks.md +357 -0
  24. package/.kiro/specs/github-actions-ci/design.md +281 -0
  25. package/.kiro/specs/github-actions-ci/requirements.md +86 -0
  26. package/.kiro/specs/github-actions-ci/tasks.md +115 -0
  27. package/.kiro/specs/nlb-calculator-test-coverage/design.md +190 -0
  28. package/.kiro/specs/nlb-calculator-test-coverage/requirements.md +84 -0
  29. package/.kiro/specs/nlb-calculator-test-coverage/tasks.md +150 -0
  30. package/.kiro/specs/production-readiness/design.md +1213 -0
  31. package/.kiro/specs/production-readiness/requirements.md +312 -0
  32. package/.kiro/specs/production-readiness/tasks.md +269 -0
  33. package/.kiro/specs/repository-cleanup/design.md +283 -0
  34. package/.kiro/specs/repository-cleanup/requirements.md +74 -0
  35. package/.kiro/specs/repository-cleanup/tasks.md +64 -0
  36. package/.kiro/steering/aws-cli-best-practices.md +41 -0
  37. package/.kiro/steering/cdk-best-practices.md +49 -0
  38. package/.kiro/steering/development-standards.md +54 -0
  39. package/.kiro/steering/docker-best-practices.md +34 -0
  40. package/.kiro/steering/documentation-style.md +151 -0
  41. package/.kiro/steering/git-best-practices.md +37 -0
  42. package/.kiro/steering/mcp-best-practices.md +95 -0
  43. package/.kiro/steering/python-best-practices.md +48 -0
  44. package/.kiro/steering/react-best-practices.md +44 -0
  45. package/.kiro/steering/security-best-practices.md +41 -0
  46. package/.kiro/steering/testing-best-practices.md +59 -0
  47. package/.kiro/steering/typescript-best-practices.md +40 -0
  48. package/CHANGELOG.md +49 -0
  49. package/CONTRIBUTING.md +258 -0
  50. package/LICENSE +19 -0
  51. package/README.md +480 -0
  52. package/SECURITY.md +117 -0
  53. package/dist/api/index.d.ts +11 -0
  54. package/dist/api/index.js +65 -0
  55. package/dist/api/types.d.ts +15 -0
  56. package/dist/api/types.js +3 -0
  57. package/dist/cli/index.d.ts +2 -0
  58. package/dist/cli/index.js +262 -0
  59. package/dist/config/ConfigManager.d.ts +40 -0
  60. package/dist/config/ConfigManager.js +238 -0
  61. package/dist/config/index.d.ts +2 -0
  62. package/dist/config/index.js +19 -0
  63. package/dist/config/types.d.ts +72 -0
  64. package/dist/config/types.js +15 -0
  65. package/dist/diff/DiffEngine.d.ts +7 -0
  66. package/dist/diff/DiffEngine.js +73 -0
  67. package/dist/diff/index.d.ts +2 -0
  68. package/dist/diff/index.js +21 -0
  69. package/dist/diff/types.d.ts +20 -0
  70. package/dist/diff/types.js +3 -0
  71. package/dist/integrations/GitLabIntegration.d.ts +7 -0
  72. package/dist/integrations/GitLabIntegration.js +45 -0
  73. package/dist/integrations/index.d.ts +2 -0
  74. package/dist/integrations/index.js +21 -0
  75. package/dist/integrations/types.d.ts +11 -0
  76. package/dist/integrations/types.js +13 -0
  77. package/dist/parser/TemplateParser.d.ts +8 -0
  78. package/dist/parser/TemplateParser.js +75 -0
  79. package/dist/parser/index.d.ts +2 -0
  80. package/dist/parser/index.js +22 -0
  81. package/dist/parser/types.d.ts +30 -0
  82. package/dist/parser/types.js +3 -0
  83. package/dist/pipeline/PipelineOrchestrator.d.ts +23 -0
  84. package/dist/pipeline/PipelineOrchestrator.js +191 -0
  85. package/dist/pipeline/index.d.ts +2 -0
  86. package/dist/pipeline/index.js +19 -0
  87. package/dist/pipeline/types.d.ts +41 -0
  88. package/dist/pipeline/types.js +13 -0
  89. package/dist/pricing/CacheManager.d.ts +75 -0
  90. package/dist/pricing/CacheManager.js +195 -0
  91. package/dist/pricing/PricingClient.d.ts +17 -0
  92. package/dist/pricing/PricingClient.js +122 -0
  93. package/dist/pricing/PricingService.d.ts +16 -0
  94. package/dist/pricing/PricingService.js +149 -0
  95. package/dist/pricing/calculators/ALBCalculator.d.ts +16 -0
  96. package/dist/pricing/calculators/ALBCalculator.js +163 -0
  97. package/dist/pricing/calculators/APIGatewayCalculator.d.ts +10 -0
  98. package/dist/pricing/calculators/APIGatewayCalculator.js +177 -0
  99. package/dist/pricing/calculators/CloudFrontCalculator.d.ts +59 -0
  100. package/dist/pricing/calculators/CloudFrontCalculator.js +151 -0
  101. package/dist/pricing/calculators/DynamoDBCalculator.d.ts +9 -0
  102. package/dist/pricing/calculators/DynamoDBCalculator.js +146 -0
  103. package/dist/pricing/calculators/EC2Calculator.d.ts +7 -0
  104. package/dist/pricing/calculators/EC2Calculator.js +80 -0
  105. package/dist/pricing/calculators/ECSCalculator.d.ts +9 -0
  106. package/dist/pricing/calculators/ECSCalculator.js +116 -0
  107. package/dist/pricing/calculators/ElastiCacheCalculator.d.ts +8 -0
  108. package/dist/pricing/calculators/ElastiCacheCalculator.js +106 -0
  109. package/dist/pricing/calculators/LambdaCalculator.d.ts +13 -0
  110. package/dist/pricing/calculators/LambdaCalculator.js +111 -0
  111. package/dist/pricing/calculators/NLBCalculator.d.ts +16 -0
  112. package/dist/pricing/calculators/NLBCalculator.js +138 -0
  113. package/dist/pricing/calculators/NatGatewayCalculator.d.ts +12 -0
  114. package/dist/pricing/calculators/NatGatewayCalculator.js +116 -0
  115. package/dist/pricing/calculators/RDSCalculator.d.ts +9 -0
  116. package/dist/pricing/calculators/RDSCalculator.js +103 -0
  117. package/dist/pricing/calculators/S3Calculator.d.ts +8 -0
  118. package/dist/pricing/calculators/S3Calculator.js +68 -0
  119. package/dist/pricing/calculators/VPCEndpointCalculator.d.ts +12 -0
  120. package/dist/pricing/calculators/VPCEndpointCalculator.js +129 -0
  121. package/dist/pricing/index.d.ts +10 -0
  122. package/dist/pricing/index.js +37 -0
  123. package/dist/pricing/types.d.ts +53 -0
  124. package/dist/pricing/types.js +22 -0
  125. package/dist/releasetag.txt +1 -0
  126. package/dist/reporter/Reporter.d.ts +18 -0
  127. package/dist/reporter/Reporter.js +412 -0
  128. package/dist/reporter/index.d.ts +2 -0
  129. package/dist/reporter/index.js +21 -0
  130. package/dist/reporter/types.d.ts +72 -0
  131. package/dist/reporter/types.js +3 -0
  132. package/dist/synthesis/SynthesisOrchestrator.d.ts +26 -0
  133. package/dist/synthesis/SynthesisOrchestrator.js +243 -0
  134. package/dist/synthesis/index.d.ts +2 -0
  135. package/dist/synthesis/index.js +19 -0
  136. package/dist/synthesis/types.d.ts +17 -0
  137. package/dist/synthesis/types.js +13 -0
  138. package/dist/threshold/ThresholdEnforcer.d.ts +29 -0
  139. package/dist/threshold/ThresholdEnforcer.js +143 -0
  140. package/dist/threshold/index.d.ts +2 -0
  141. package/dist/threshold/index.js +19 -0
  142. package/dist/threshold/types.d.ts +15 -0
  143. package/dist/threshold/types.js +17 -0
  144. package/docs/CALCULATORS.md +820 -0
  145. package/docs/CI_CD.md +608 -0
  146. package/docs/CONFIGURATION.md +407 -0
  147. package/docs/DEVELOPMENT.md +387 -0
  148. package/docs/RELEASE.md +223 -0
  149. package/docs/TROUBLESHOOTING.md +847 -0
  150. package/examples/.cdk-cost-analyzer.yml +85 -0
  151. package/examples/.gitlab-ci.yml +125 -0
  152. package/examples/api-usage.js +26 -0
  153. package/examples/complex/base.json +16 -0
  154. package/examples/complex/target.json +29 -0
  155. package/examples/monorepo/.gitlab-ci.yml +251 -0
  156. package/examples/monorepo/README.md +341 -0
  157. package/examples/monorepo/package.json +27 -0
  158. package/examples/monorepo/packages/backend-infra/.cdk-cost-analyzer.yml +34 -0
  159. package/examples/monorepo/packages/backend-infra/bin/app.ts +16 -0
  160. package/examples/monorepo/packages/backend-infra/cdk.json +7 -0
  161. package/examples/monorepo/packages/backend-infra/lib/backend-stack.ts +128 -0
  162. package/examples/monorepo/packages/backend-infra/package.json +30 -0
  163. package/examples/monorepo/packages/backend-infra/tsconfig.json +11 -0
  164. package/examples/monorepo/packages/data-infra/.cdk-cost-analyzer.yml +38 -0
  165. package/examples/monorepo/packages/data-infra/bin/app.ts +16 -0
  166. package/examples/monorepo/packages/data-infra/cdk.json +7 -0
  167. package/examples/monorepo/packages/data-infra/lib/data-stack.ts +121 -0
  168. package/examples/monorepo/packages/data-infra/package.json +30 -0
  169. package/examples/monorepo/packages/data-infra/tsconfig.json +11 -0
  170. package/examples/monorepo/packages/frontend-infra/.cdk-cost-analyzer.yml +31 -0
  171. package/examples/monorepo/packages/frontend-infra/bin/app.ts +16 -0
  172. package/examples/monorepo/packages/frontend-infra/cdk.json +7 -0
  173. package/examples/monorepo/packages/frontend-infra/lib/frontend-stack.ts +60 -0
  174. package/examples/monorepo/packages/frontend-infra/package.json +30 -0
  175. package/examples/monorepo/packages/frontend-infra/tsconfig.json +11 -0
  176. package/examples/monorepo/tsconfig.json +35 -0
  177. package/examples/multi-stack/.cdk-cost-analyzer.yml +72 -0
  178. package/examples/multi-stack/.gitlab-ci.yml +184 -0
  179. package/examples/multi-stack/README.md +279 -0
  180. package/examples/multi-stack/bin/app.ts +36 -0
  181. package/examples/multi-stack/cdk.json +72 -0
  182. package/examples/multi-stack/lib/compute-stack.ts +128 -0
  183. package/examples/multi-stack/lib/networking-stack.ts +69 -0
  184. package/examples/multi-stack/lib/storage-stack.ts +141 -0
  185. package/examples/multi-stack/package-lock.json +4437 -0
  186. package/examples/multi-stack/package.json +42 -0
  187. package/examples/multi-stack/tsconfig.json +34 -0
  188. package/examples/simple/base.json +8 -0
  189. package/examples/simple/target.json +14 -0
  190. package/examples/single-stack/.NVP +0 -0
  191. package/examples/single-stack/.cdk-cost-analyzer.yml +52 -0
  192. package/examples/single-stack/.gitlab-ci.yml +126 -0
  193. package/examples/single-stack/README.md +184 -0
  194. package/examples/single-stack/UeK +0 -0
  195. package/examples/single-stack/bin/app.ts +16 -0
  196. package/examples/single-stack/cdk.json +72 -0
  197. package/examples/single-stack/lib/infrastructure-stack.ts +119 -0
  198. package/examples/single-stack/package-lock.json +4443 -0
  199. package/examples/single-stack/package.json +38 -0
  200. package/examples/single-stack/tsconfig.json +34 -0
  201. package/package.json +139 -0
  202. package/test-cdk-project/README-COMPUTE.md +141 -0
  203. package/test-cdk-project/README.md +95 -0
  204. package/test-cdk-project/app-with-compute.js +102 -0
  205. package/test-cdk-project/app.js +81 -0
  206. package/test-cdk-project/cdk-compute.json +3 -0
  207. package/test-cdk-project/cdk.context.json +7 -0
  208. package/test-cdk-project/cdk.json +3 -0
  209. package/test-cdk-project/cdk.out/TestStack.assets.json +21 -0
  210. package/test-cdk-project/cdk.out/TestStack.template.json +115 -0
  211. package/test-cdk-project/cdk.out/cdk.out +1 -0
  212. package/test-cdk-project/cdk.out/manifest.json +503 -0
  213. package/test-cdk-project/cdk.out/tree.json +1 -0
  214. package/test-cdk-project/cdk.out.base/TestStack.assets.json +21 -0
  215. package/test-cdk-project/cdk.out.base/TestStack.template.json +115 -0
  216. package/test-cdk-project/cdk.out.base/cdk.out +1 -0
  217. package/test-cdk-project/cdk.out.base/manifest.json +503 -0
  218. package/test-cdk-project/cdk.out.base/tree.json +1 -0
  219. package/test-cdk-project/cdk.out.target/TestStack.assets.json +21 -0
  220. package/test-cdk-project/cdk.out.target/TestStack.template.json +183 -0
  221. package/test-cdk-project/cdk.out.target/cdk.out +1 -0
  222. package/test-cdk-project/cdk.out.target/manifest.json +521 -0
  223. package/test-cdk-project/cdk.out.target/tree.json +1 -0
  224. package/test-cdk-project/package-lock.json +422 -0
  225. package/test-cdk-project/package.json +17 -0
  226. package/tools/workflows/README.md +102 -0
  227. package/tools/workflows/validate-workflows.js +109 -0
  228. package/tools/workflows/workflow-utils.ts +181 -0
package/docs/CI_CD.md ADDED
@@ -0,0 +1,608 @@
1
+ # CI/CD Integration Guide
2
+
3
+ This guide covers integrating CDK Cost Analyzer into your CI/CD pipelines for automated testing and cost analysis.
4
+
5
+ ## Table of Contents
6
+
7
+ - [GitHub Actions](#github-actions)
8
+ - [GitLab CI](#gitlab-ci)
9
+ - [General Best Practices](#general-best-practices)
10
+
11
+ ---
12
+
13
+ ## GitHub Actions
14
+
15
+ ### Basic Setup
16
+
17
+ Create `.github/workflows/ci.yml`:
18
+
19
+ ```yaml
20
+ name: CI
21
+
22
+ on:
23
+ push:
24
+ branches: ['**']
25
+ pull_request:
26
+ branches: ['**']
27
+
28
+ jobs:
29
+ test:
30
+ runs-on: ubuntu-latest
31
+ steps:
32
+ - uses: actions/checkout@v4
33
+ - uses: actions/setup-node@v4
34
+ with:
35
+ node-version: '18.x'
36
+ cache: 'npm'
37
+ - run: npm ci
38
+ - run: npm run eslint
39
+ - run: npm run lint
40
+ - run: npm run build
41
+ - run: npm run test:silent
42
+ ```
43
+
44
+ ### Configuration Options
45
+
46
+ #### Trigger Events
47
+
48
+ ```yaml
49
+ # Run on all branches
50
+ on:
51
+ push:
52
+ branches: ['**']
53
+ pull_request:
54
+ branches: ['**']
55
+
56
+ # Run only on specific branches
57
+ on:
58
+ push:
59
+ branches: [main, develop]
60
+ pull_request:
61
+ branches: [main]
62
+
63
+ # Run on specific paths
64
+ on:
65
+ push:
66
+ paths:
67
+ - 'src/**'
68
+ - 'test/**'
69
+ - 'package.json'
70
+ ```
71
+
72
+ #### Multi-Version Testing
73
+
74
+ ```yaml
75
+ jobs:
76
+ test:
77
+ runs-on: ubuntu-latest
78
+ strategy:
79
+ matrix:
80
+ node-version: [18.x, 20.x, 22.x]
81
+ steps:
82
+ - uses: actions/checkout@v4
83
+ - uses: actions/setup-node@v4
84
+ with:
85
+ node-version: ${{ matrix.node-version }}
86
+ cache: 'npm'
87
+ - run: npm ci
88
+ - run: npm run build
89
+ - run: npm run test:silent
90
+ ```
91
+
92
+ #### Test Coverage
93
+
94
+ ```yaml
95
+ jobs:
96
+ test:
97
+ runs-on: ubuntu-latest
98
+ steps:
99
+ - uses: actions/checkout@v4
100
+ - uses: actions/setup-node@v4
101
+ with:
102
+ node-version: '18.x'
103
+ cache: 'npm'
104
+ - run: npm ci
105
+ - run: npm run test:coverage
106
+
107
+ - name: Upload coverage
108
+ uses: codecov/codecov-action@v4
109
+ with:
110
+ files: ./coverage/coverage-final.json
111
+ ```
112
+
113
+ ### Status Badge
114
+
115
+ Add to your README:
116
+
117
+ ```markdown
118
+ [![CI](https://github.com/USERNAME/REPOSITORY/actions/workflows/ci.yml/badge.svg)](https://github.com/USERNAME/REPOSITORY/actions/workflows/ci.yml)
119
+ ```
120
+
121
+ ### Complete Example
122
+
123
+ ```yaml
124
+ name: CI
125
+
126
+ on:
127
+ push:
128
+ branches: ['**']
129
+ paths:
130
+ - 'src/**'
131
+ - 'test/**'
132
+ - 'package.json'
133
+ - 'package-lock.json'
134
+ pull_request:
135
+ branches: ['**']
136
+
137
+ concurrency:
138
+ group: ${{ github.workflow }}-${{ github.ref }}
139
+ cancel-in-progress: true
140
+
141
+ jobs:
142
+ test:
143
+ runs-on: ubuntu-latest
144
+ strategy:
145
+ fail-fast: true
146
+ matrix:
147
+ node-version: [18.x, 20.x, 22.x]
148
+
149
+ steps:
150
+ - name: Checkout code
151
+ uses: actions/checkout@v4
152
+
153
+ - name: Setup Node.js
154
+ uses: actions/setup-node@v4
155
+ with:
156
+ node-version: ${{ matrix.node-version }}
157
+ cache: 'npm'
158
+
159
+ - name: Install dependencies
160
+ run: npm ci
161
+
162
+ - name: Run linting
163
+ run: npm run eslint
164
+
165
+ - name: Run type checking
166
+ run: npm run lint
167
+
168
+ - name: Build project
169
+ run: npm run build
170
+
171
+ - name: Run tests
172
+ run: npm run test:silent
173
+ ```
174
+
175
+ ---
176
+
177
+ ## GitLab CI
178
+
179
+ ### Basic Setup
180
+
181
+ Add to `.gitlab-ci.yml`:
182
+
183
+ ```yaml
184
+ stages:
185
+ - build
186
+ - test
187
+ - cost-analysis
188
+ - deploy
189
+
190
+ variables:
191
+ AWS_REGION: eu-central-1
192
+
193
+ install:
194
+ stage: build
195
+ image: node:18
196
+ script:
197
+ - npm ci
198
+ cache:
199
+ key: ${CI_COMMIT_REF_SLUG}
200
+ paths:
201
+ - node_modules/
202
+ artifacts:
203
+ paths:
204
+ - node_modules/
205
+ expire_in: 1 hour
206
+
207
+ cost-analysis:
208
+ stage: cost-analysis
209
+ image: node:18
210
+ dependencies:
211
+ - install
212
+ before_script:
213
+ - npm install -g cdk-cost-analyzer
214
+ script:
215
+ - |
216
+ cdk-cost-analyzer pipeline \
217
+ --synth \
218
+ --cdk-app-path ./infrastructure \
219
+ --region $AWS_REGION \
220
+ --format markdown \
221
+ --post-to-gitlab
222
+ only:
223
+ - merge_requests
224
+ ```
225
+
226
+ ### AWS Credentials
227
+
228
+ Configure in **Settings > CI/CD > Variables**:
229
+ - `AWS_ACCESS_KEY_ID` (masked)
230
+ - `AWS_SECRET_ACCESS_KEY` (masked)
231
+ - `AWS_REGION`
232
+
233
+ ### Cost Analysis Options
234
+
235
+ #### Template-Based Analysis
236
+
237
+ ```yaml
238
+ cost-analysis:
239
+ stage: cost-analysis
240
+ image: node:18
241
+ script:
242
+ - |
243
+ cdk-cost-analyzer compare \
244
+ ./cdk.out.base/MyStack.template.json \
245
+ ./cdk.out.target/MyStack.template.json \
246
+ --region $AWS_REGION \
247
+ --format markdown \
248
+ > cost-report.md
249
+ only:
250
+ - merge_requests
251
+ ```
252
+
253
+ #### With Automatic Synthesis
254
+
255
+ ```yaml
256
+ cost-analysis:
257
+ stage: cost-analysis
258
+ image: node:18
259
+ script:
260
+ - |
261
+ cdk-cost-analyzer pipeline \
262
+ --synth \
263
+ --cdk-app-path ./infrastructure \
264
+ --region $AWS_REGION \
265
+ --config .cdk-cost-analyzer.yml \
266
+ --environment $CI_ENVIRONMENT_NAME \
267
+ --format markdown \
268
+ --post-to-gitlab
269
+ only:
270
+ - merge_requests
271
+ ```
272
+
273
+ ### Advanced Configurations
274
+
275
+ #### Monorepo Setup
276
+
277
+ ```yaml
278
+ .cost-analysis-template: &cost-analysis
279
+ stage: cost-analysis
280
+ image: node:18
281
+ before_script:
282
+ - npm install -g cdk-cost-analyzer
283
+ script:
284
+ - |
285
+ cdk-cost-analyzer pipeline \
286
+ --synth \
287
+ --cdk-app-path $CDK_APP_PATH \
288
+ --region $AWS_REGION \
289
+ --format markdown \
290
+ --post-to-gitlab
291
+ only:
292
+ - merge_requests
293
+
294
+ cost-analysis:infrastructure:
295
+ <<: *cost-analysis
296
+ variables:
297
+ CDK_APP_PATH: ./packages/infrastructure
298
+
299
+ cost-analysis:services:
300
+ <<: *cost-analysis
301
+ variables:
302
+ CDK_APP_PATH: ./packages/services/infrastructure
303
+ ```
304
+
305
+ #### Environment-Specific Pipelines
306
+
307
+ ```yaml
308
+ cost-analysis:production:
309
+ stage: cost-analysis
310
+ image: node:18
311
+ script:
312
+ - |
313
+ cdk-cost-analyzer pipeline \
314
+ --environment production \
315
+ --format markdown \
316
+ --post-to-gitlab
317
+ only:
318
+ - main
319
+
320
+ cost-analysis:development:
321
+ stage: cost-analysis
322
+ image: node:18
323
+ script:
324
+ - |
325
+ cdk-cost-analyzer pipeline \
326
+ --environment development \
327
+ --format markdown \
328
+ --post-to-gitlab
329
+ only:
330
+ - merge_requests
331
+ ```
332
+
333
+ #### With Pricing Cache
334
+
335
+ ```yaml
336
+ cost-analysis:
337
+ stage: cost-analysis
338
+ image: node:18
339
+ cache:
340
+ key: pricing-cache
341
+ paths:
342
+ - .cdk-cost-analyzer-cache/
343
+ script:
344
+ - cdk-cost-analyzer pipeline ...
345
+ only:
346
+ - merge_requests
347
+ ```
348
+
349
+ ### Exit Codes
350
+
351
+ - **0**: Analysis successful, no threshold violations
352
+ - **1**: Analysis failed (synthesis error, API error)
353
+ - **2**: Analysis successful, but error threshold exceeded
354
+
355
+ Handle exit codes:
356
+
357
+ ```yaml
358
+ cost-analysis:
359
+ script:
360
+ - cdk-cost-analyzer pipeline ... || EXIT_CODE=$?
361
+ - |
362
+ if [ $EXIT_CODE -eq 2 ]; then
363
+ echo "Cost threshold exceeded - requires approval"
364
+ fi
365
+ allow_failure:
366
+ exit_codes: [2] # Allow threshold violations but mark as warning
367
+ ```
368
+
369
+ ### Complete Example
370
+
371
+ ```yaml
372
+ stages:
373
+ - build
374
+ - test
375
+ - cost-analysis
376
+ - deploy
377
+
378
+ variables:
379
+ AWS_REGION: eu-central-1
380
+ CDK_APP_PATH: ./infrastructure
381
+
382
+ .node-cache: &node-cache
383
+ cache:
384
+ key: ${CI_COMMIT_REF_SLUG}
385
+ paths:
386
+ - node_modules/
387
+ - ${CDK_APP_PATH}/node_modules/
388
+ - .cdk-cost-analyzer-cache/
389
+
390
+ install:
391
+ stage: build
392
+ image: node:18
393
+ <<: *node-cache
394
+ script:
395
+ - npm ci
396
+ - cd ${CDK_APP_PATH} && npm ci
397
+ artifacts:
398
+ paths:
399
+ - node_modules/
400
+ - ${CDK_APP_PATH}/node_modules/
401
+ expire_in: 1 hour
402
+
403
+ test:
404
+ stage: test
405
+ image: node:18
406
+ dependencies:
407
+ - install
408
+ script:
409
+ - npm test
410
+ - cd ${CDK_APP_PATH} && npm test
411
+
412
+ synthesize:
413
+ stage: test
414
+ image: node:18
415
+ dependencies:
416
+ - install
417
+ script:
418
+ - cd ${CDK_APP_PATH}
419
+ - npx cdk synth --all
420
+ artifacts:
421
+ paths:
422
+ - ${CDK_APP_PATH}/cdk.out
423
+ expire_in: 1 hour
424
+ only:
425
+ changes:
426
+ - infrastructure/**/*
427
+
428
+ cost-analysis:
429
+ stage: cost-analysis
430
+ image: node:18
431
+ dependencies:
432
+ - install
433
+ - synthesize
434
+ <<: *node-cache
435
+ before_script:
436
+ - npm install -g cdk-cost-analyzer
437
+ script:
438
+ - |
439
+ cdk-cost-analyzer pipeline \
440
+ --synth \
441
+ --cdk-app-path ${CDK_APP_PATH} \
442
+ --region ${AWS_REGION} \
443
+ --config .cdk-cost-analyzer.yml \
444
+ --environment ${CI_ENVIRONMENT_NAME:-development} \
445
+ --format markdown \
446
+ --post-to-gitlab
447
+ allow_failure:
448
+ exit_codes: [2]
449
+ only:
450
+ - merge_requests
451
+ only:
452
+ changes:
453
+ - infrastructure/**/*
454
+ - .cdk-cost-analyzer.yml
455
+
456
+ deploy:
457
+ stage: deploy
458
+ image: node:18
459
+ dependencies:
460
+ - install
461
+ - synthesize
462
+ script:
463
+ - cd ${CDK_APP_PATH}
464
+ - npx cdk deploy --all --require-approval never
465
+ only:
466
+ - main
467
+ when: manual
468
+ ```
469
+
470
+ ---
471
+
472
+ ## General Best Practices
473
+
474
+ ### 1. Cache Dependencies
475
+
476
+ Always cache dependencies to speed up builds:
477
+
478
+ **GitHub Actions:**
479
+ ```yaml
480
+ - uses: actions/setup-node@v4
481
+ with:
482
+ cache: 'npm'
483
+ ```
484
+
485
+ **GitLab CI:**
486
+ ```yaml
487
+ cache:
488
+ key: ${CI_COMMIT_REF_SLUG}
489
+ paths:
490
+ - node_modules/
491
+ ```
492
+
493
+ ### 2. Run Tests Silently
494
+
495
+ Use silent mode to prevent timeout issues:
496
+
497
+ ```bash
498
+ npm run test:silent
499
+ ```
500
+
501
+ ### 3. Only Run on Changes
502
+
503
+ Run workflows only when relevant files change:
504
+
505
+ **GitHub Actions:**
506
+ ```yaml
507
+ on:
508
+ push:
509
+ paths:
510
+ - 'src/**'
511
+ - 'test/**'
512
+ ```
513
+
514
+ **GitLab CI:**
515
+ ```yaml
516
+ only:
517
+ changes:
518
+ - infrastructure/**/*
519
+ ```
520
+
521
+ ### 4. Use Configuration Files
522
+
523
+ Store configuration in `.cdk-cost-analyzer.yml`:
524
+
525
+ ```yaml
526
+ thresholds:
527
+ environments:
528
+ production:
529
+ error: 100
530
+ development:
531
+ error: 500
532
+ ```
533
+
534
+ ### 5. Separate Synthesis
535
+
536
+ Run synthesis in a separate job for better visibility and debugging.
537
+
538
+ ### 6. Pin Versions
539
+
540
+ Use specific versions for stability:
541
+
542
+ **GitHub Actions:**
543
+ ```yaml
544
+ - uses: actions/checkout@v4
545
+ - uses: actions/setup-node@v4
546
+ ```
547
+
548
+ **GitLab CI:**
549
+ ```yaml
550
+ image: node:18 # Specific version
551
+ ```
552
+
553
+ ## Troubleshooting
554
+
555
+ ### Tests Failing in CI but Passing Locally
556
+
557
+ 1. Verify Node.js version matches local environment
558
+ 2. Check for environment-specific dependencies
559
+ 3. Ensure all test files are committed
560
+ 4. Review test output in CI logs
561
+ 5. Run tests locally with same Node.js version as CI
562
+
563
+ ### Cache Not Working
564
+
565
+ 1. Verify cache configuration is correct
566
+ 2. Ensure lock files are committed
567
+ 3. Check cache size limits
568
+
569
+ ### Timeout Issues
570
+
571
+ 1. Use silent test mode
572
+ 2. Increase timeout in workflow configuration
573
+ 3. Split tests into parallel jobs
574
+
575
+ ### AWS Credential Issues
576
+
577
+ 1. Verify credentials are configured as CI/CD variables
578
+ 2. Check variable names match expected format
579
+ 3. Ensure credentials have necessary IAM permissions for Pricing API
580
+
581
+ ## Running Checks Locally
582
+
583
+ Before pushing code:
584
+
585
+ ```bash
586
+ # Install dependencies
587
+ npm ci
588
+
589
+ # Run linting
590
+ npm run eslint
591
+
592
+ # Run type checking
593
+ npm run lint
594
+
595
+ # Build the project
596
+ npm run build
597
+
598
+ # Run tests
599
+ npm run test:silent
600
+ ```
601
+
602
+ ## Additional Resources
603
+
604
+ - [Configuration Guide](./CONFIGURATION.md) - Detailed configuration options
605
+ - [Development Guide](./DEVELOPMENT.md) - Local development and testing
606
+ - [Troubleshooting Guide](./TROUBLESHOOTING.md) - Common issues and solutions
607
+ - [GitHub Actions Documentation](https://docs.github.com/en/actions)
608
+ - [GitLab CI/CD Documentation](https://docs.gitlab.com/ee/ci/)