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
@@ -0,0 +1,847 @@
1
+ # Troubleshooting Guide
2
+
3
+ This guide covers common issues and solutions when using CDK Cost Analyzer.
4
+
5
+ ## Table of Contents
6
+
7
+ - [CDK Synthesis Errors](#cdk-synthesis-errors)
8
+ - [AWS Credential Issues](#aws-credential-issues)
9
+ - [Configuration Validation Errors](#configuration-validation-errors)
10
+ - [Pricing API Failures](#pricing-api-failures)
11
+ - [GitLab CI Common Issues](#gitlab-ci-common-issues)
12
+ - [Template Parsing Errors](#template-parsing-errors)
13
+ - [Performance Issues](#performance-issues)
14
+
15
+ ## CDK Synthesis Errors
16
+
17
+ ### Error: CDK synthesis timed out after 20 seconds
18
+
19
+ **Symptoms:**
20
+ ```
21
+ Error: CDK synthesis timed out after 20 seconds
22
+ ```
23
+
24
+ **Causes:**
25
+ - CDK synthesis process hanging or taking too long
26
+ - Complex CDK application with many resources
27
+ - Network issues during synthesis (e.g., VPC lookups)
28
+ - Infinite loops or deadlocks in CDK code
29
+
30
+ **Solutions:**
31
+
32
+ 1. **Optimize CDK application:**
33
+ ```typescript
34
+ // Avoid expensive lookups in synthesis
35
+ // Use context values instead of runtime lookups
36
+ const vpc = Vpc.fromLookup(this, 'Vpc', {
37
+ vpcId: this.node.tryGetContext('vpc-id') // Use context
38
+ });
39
+ ```
40
+
41
+ 2. **Reduce synthesis complexity:**
42
+ ```typescript
43
+ // Split large stacks into smaller ones
44
+ // Avoid complex computations during synthesis
45
+ // Use lazy evaluation where possible
46
+ ```
47
+
48
+ 3. **Check for infinite loops:**
49
+ ```typescript
50
+ // Review custom constructs for potential infinite recursion
51
+ // Check for circular dependencies between constructs
52
+ ```
53
+
54
+ 4. **Use custom synthesis command with timeout:**
55
+ ```yaml
56
+ # .cdk-cost-analyzer.yml
57
+ synthesis:
58
+ customCommand: "timeout 60 npx cdk synth" # 60 second timeout
59
+ ```
60
+
61
+ 5. **Debug synthesis locally:**
62
+ ```bash
63
+ cd infrastructure
64
+ time npx cdk synth --all # Measure synthesis time
65
+ ```
66
+
67
+ **Note:** The 20-second timeout is designed to prevent hanging processes in CI/CD environments while providing faster feedback. The timeout includes improved process cleanup with graceful termination (SIGTERM) followed by force termination (SIGKILL) after 2 seconds if needed. If your CDK application legitimately requires more time, consider optimizing the synthesis process or using a custom command with extended timeout.
68
+
69
+ ### Error: CDK synthesis failed with exit code 1
70
+
71
+ **Symptoms:**
72
+ ```
73
+ Error: CDK synthesis failed with exit code 1
74
+ CDK output: Error: Cannot find module '@aws-cdk/core'
75
+ ```
76
+
77
+ **Causes:**
78
+ - Missing CDK dependencies
79
+ - Incorrect CDK application path
80
+ - TypeScript compilation errors in CDK code
81
+
82
+ **Solutions:**
83
+
84
+ 1. **Install CDK dependencies:**
85
+ ```bash
86
+ cd infrastructure
87
+ npm install
88
+ ```
89
+
90
+ 2. **Verify CDK application compiles:**
91
+ ```bash
92
+ cd infrastructure
93
+ npm run build
94
+ npx cdk synth
95
+ ```
96
+
97
+ 3. **Check CDK application path:**
98
+ ```bash
99
+ # Ensure --cdk-app-path points to correct directory
100
+ cdk-cost-analyzer pipeline --cdk-app-path ./infrastructure
101
+ ```
102
+
103
+ 4. **Check for TypeScript errors:**
104
+ ```bash
105
+ cd infrastructure
106
+ npx tsc --noEmit
107
+ ```
108
+
109
+ ### Error: No stacks found in CDK application
110
+
111
+ **Symptoms:**
112
+ ```
113
+ Error: No CloudFormation templates found in cdk.out directory
114
+ ```
115
+
116
+ **Causes:**
117
+ - CDK synthesis produced no stacks
118
+ - Incorrect output directory
119
+ - CDK app has no stack instantiations
120
+
121
+ **Solutions:**
122
+
123
+ 1. **Verify CDK app creates stacks:**
124
+ ```typescript
125
+ // app.ts
126
+ import * as cdk from 'aws-cdk-lib';
127
+ import { MyStack } from './stacks/MyStack';
128
+
129
+ const app = new cdk.App();
130
+ new MyStack(app, 'MyStack'); // Ensure stack is instantiated
131
+ ```
132
+
133
+ 2. **Check synthesis output:**
134
+ ```bash
135
+ cd infrastructure
136
+ npx cdk synth --all
137
+ ls cdk.out/*.template.json
138
+ ```
139
+
140
+ 3. **Specify custom output directory:**
141
+ ```bash
142
+ cdk-cost-analyzer pipeline \
143
+ --cdk-app-path ./infrastructure \
144
+ --synthesis-output ./infrastructure/cdk.out
145
+ ```
146
+
147
+ ### Error: CDK context value required
148
+
149
+ **Symptoms:**
150
+ ```
151
+ Error: Context value 'vpc-id' is required but not provided
152
+ ```
153
+
154
+ **Causes:**
155
+ - Missing CDK context values
156
+ - Context not passed to synthesis
157
+
158
+ **Solutions:**
159
+
160
+ 1. **Provide context in configuration:**
161
+ ```yaml
162
+ # .cdk-cost-analyzer.yml
163
+ synthesis:
164
+ context:
165
+ vpc-id: vpc-12345678
166
+ environment: production
167
+ ```
168
+
169
+ 2. **Set context via environment variables:**
170
+ ```bash
171
+ export CDK_CONTEXT_VPC_ID=vpc-12345678
172
+ cdk-cost-analyzer pipeline --synth
173
+ ```
174
+
175
+ 3. **Use cdk.context.json:**
176
+ ```json
177
+ {
178
+ "vpc-id": "vpc-12345678",
179
+ "environment": "production"
180
+ }
181
+ ```
182
+
183
+ ## AWS Credential Issues
184
+
185
+ ### Error: AWS credentials not configured
186
+
187
+ **Symptoms:**
188
+ ```
189
+ Error: AWS credentials not configured
190
+ Unable to locate credentials
191
+ ```
192
+
193
+ **Causes:**
194
+ - No AWS credentials in environment
195
+ - Invalid credential format
196
+ - Expired temporary credentials
197
+
198
+ **Solutions:**
199
+
200
+ 1. **Configure AWS credentials:**
201
+ ```bash
202
+ # Via environment variables
203
+ export AWS_ACCESS_KEY_ID=your_access_key
204
+ export AWS_SECRET_ACCESS_KEY=your_secret_key
205
+ export AWS_REGION=eu-central-1
206
+
207
+ # Or via AWS CLI
208
+ aws configure
209
+ ```
210
+
211
+ 2. **Verify credentials work:**
212
+ ```bash
213
+ aws sts get-caller-identity --no-cli-pager
214
+ ```
215
+
216
+ 3. **For GitLab CI, add CI/CD variables:**
217
+ - Go to **Settings > CI/CD > Variables**
218
+ - Add `AWS_ACCESS_KEY_ID` (masked)
219
+ - Add `AWS_SECRET_ACCESS_KEY` (masked)
220
+ - Add `AWS_REGION`
221
+
222
+ ### Error: Access Denied when calling AWS Pricing API
223
+
224
+ **Symptoms:**
225
+ ```
226
+ Error: Failed to fetch pricing: AccessDenied
227
+ User is not authorized to perform: pricing:GetProducts
228
+ ```
229
+
230
+ **Causes:**
231
+ - IAM user/role lacks pricing API permissions
232
+ - Service Control Policies blocking access
233
+
234
+ **Solutions:**
235
+
236
+ 1. **Add pricing permissions to IAM policy:**
237
+ ```json
238
+ {
239
+ "Version": "2012-10-17",
240
+ "Statement": [
241
+ {
242
+ "Effect": "Allow",
243
+ "Action": [
244
+ "pricing:GetProducts",
245
+ "pricing:DescribeServices"
246
+ ],
247
+ "Resource": "*"
248
+ }
249
+ ]
250
+ }
251
+ ```
252
+
253
+ 2. **Use IAM role with pricing permissions:**
254
+ ```yaml
255
+ # GitLab CI with IAM role
256
+ cost-analysis:
257
+ id_tokens:
258
+ AWS_OIDC_TOKEN:
259
+ aud: https://gitlab.com
260
+ before_script:
261
+ - export $(printf "AWS_ACCESS_KEY_ID=%s AWS_SECRET_ACCESS_KEY=%s AWS_SESSION_TOKEN=%s" \
262
+ $(aws sts assume-role-with-web-identity \
263
+ --role-arn ${AWS_ROLE_ARN} \
264
+ --role-session-name "GitLabRunner-${CI_PROJECT_ID}-${CI_PIPELINE_ID}" \
265
+ --web-identity-token ${AWS_OIDC_TOKEN} \
266
+ --duration-seconds 3600 \
267
+ --query 'Credentials.[AccessKeyId,SecretAccessKey,SessionToken]' \
268
+ --output text))
269
+ ```
270
+
271
+ ### Error: Invalid AWS region
272
+
273
+ **Symptoms:**
274
+ ```
275
+ Error: Invalid region: eu-central-1a
276
+ ```
277
+
278
+ **Causes:**
279
+ - Availability zone specified instead of region
280
+ - Typo in region name
281
+
282
+ **Solutions:**
283
+
284
+ 1. **Use region, not availability zone:**
285
+ ```bash
286
+ # Wrong
287
+ --region eu-central-1a
288
+
289
+ # Correct
290
+ --region eu-central-1
291
+ ```
292
+
293
+ 2. **Verify region name:**
294
+ ```bash
295
+ aws ec2 describe-regions --query 'Regions[].RegionName' --no-cli-pager
296
+ ```
297
+
298
+ ## Configuration Validation Errors
299
+
300
+ ### Error: Invalid configuration file syntax
301
+
302
+ **Symptoms:**
303
+ ```
304
+ Error: Invalid configuration
305
+ YAML parse error: bad indentation
306
+ ```
307
+
308
+ **Causes:**
309
+ - Invalid YAML/JSON syntax
310
+ - Incorrect indentation
311
+ - Missing quotes around special characters
312
+
313
+ **Solutions:**
314
+
315
+ 1. **Validate YAML syntax:**
316
+ ```bash
317
+ # Use online YAML validator or
318
+ npm install -g js-yaml
319
+ js-yaml .cdk-cost-analyzer.yml
320
+ ```
321
+
322
+ 2. **Check indentation (use spaces, not tabs):**
323
+ ```yaml
324
+ # Wrong
325
+ thresholds:
326
+ default: # Tab character
327
+ warning: 50
328
+
329
+ # Correct
330
+ thresholds:
331
+ default: # Two spaces
332
+ warning: 50
333
+ ```
334
+
335
+ 3. **Quote special values:**
336
+ ```yaml
337
+ # Wrong
338
+ customCommand: npx cdk synth --all
339
+
340
+ # Correct
341
+ customCommand: "npx cdk synth --all"
342
+ ```
343
+
344
+ ### Error: Negative threshold value
345
+
346
+ **Symptoms:**
347
+ ```
348
+ Error: Invalid configuration
349
+ Validation errors:
350
+ - thresholds.default.warning must be non-negative
351
+ ```
352
+
353
+ **Causes:**
354
+ - Negative values in configuration
355
+ - Invalid number format
356
+
357
+ **Solutions:**
358
+
359
+ 1. **Use positive numbers:**
360
+ ```yaml
361
+ # Wrong
362
+ thresholds:
363
+ default:
364
+ warning: -50
365
+
366
+ # Correct
367
+ thresholds:
368
+ default:
369
+ warning: 50
370
+ ```
371
+
372
+ 2. **Ensure numbers are not strings:**
373
+ ```yaml
374
+ # Wrong
375
+ thresholds:
376
+ default:
377
+ warning: "50" # String
378
+
379
+ # Correct
380
+ thresholds:
381
+ default:
382
+ warning: 50 # Number
383
+ ```
384
+
385
+ ### Error: Warning threshold exceeds error threshold
386
+
387
+ **Symptoms:**
388
+ ```
389
+ Warning: Warning threshold (200) exceeds error threshold (100)
390
+ ```
391
+
392
+ **Causes:**
393
+ - Warning threshold higher than error threshold
394
+ - Logical configuration error
395
+
396
+ **Solutions:**
397
+
398
+ 1. **Ensure warning < error:**
399
+ ```yaml
400
+ # Wrong
401
+ thresholds:
402
+ default:
403
+ warning: 200
404
+ error: 100
405
+
406
+ # Correct
407
+ thresholds:
408
+ default:
409
+ warning: 50
410
+ error: 200
411
+ ```
412
+
413
+ ## Pricing API Failures
414
+
415
+ ### Error: Too many requests (throttling)
416
+
417
+ **Symptoms:**
418
+ ```
419
+ Error: Failed to fetch pricing: TooManyRequestsException
420
+ Rate exceeded
421
+ ```
422
+
423
+ **Causes:**
424
+ - Too many API calls in short time
425
+ - Multiple pipelines running simultaneously
426
+ - No caching enabled
427
+
428
+ **Solutions:**
429
+
430
+ 1. **Enable pricing cache:**
431
+ ```yaml
432
+ # .cdk-cost-analyzer.yml
433
+ cache:
434
+ enabled: true
435
+ durationHours: 24
436
+ ```
437
+
438
+ 2. **Use GitLab CI cache:**
439
+ ```yaml
440
+ cost-analysis:
441
+ cache:
442
+ key: pricing-cache
443
+ paths:
444
+ - .cdk-cost-analyzer-cache/
445
+ ```
446
+
447
+ 3. **Add delays between parallel jobs:**
448
+ ```yaml
449
+ cost-analysis:stack1:
450
+ script:
451
+ - sleep $((RANDOM % 10)) # Random delay 0-10 seconds
452
+ - cdk-cost-analyzer ...
453
+ ```
454
+
455
+ ### Error: Pricing data not available
456
+
457
+ **Symptoms:**
458
+ ```
459
+ Warning: Pricing data not available for AWS::CustomResource::Type in region eu-central-1
460
+ ```
461
+
462
+ **Causes:**
463
+ - Unsupported resource type
464
+ - Resource type not available in region
465
+ - New AWS service not yet in pricing API
466
+
467
+ **Solutions:**
468
+
469
+ 1. **Exclude unsupported resources:**
470
+ ```yaml
471
+ # .cdk-cost-analyzer.yml
472
+ exclusions:
473
+ resourceTypes:
474
+ - AWS::CustomResource::Type
475
+ ```
476
+
477
+ 2. **Check resource availability in region:**
478
+ ```bash
479
+ aws pricing describe-services --service-code AmazonEC2 --region us-east-1 --no-cli-pager
480
+ ```
481
+
482
+ 3. **Accept unknown costs:**
483
+ - Tool will mark resource as "unknown cost"
484
+ - Analysis continues for other resources
485
+ - Review report for unsupported resources
486
+
487
+ ### Error: Network timeout
488
+
489
+ **Symptoms:**
490
+ ```
491
+ Error: Failed to fetch pricing: ETIMEDOUT
492
+ Connection timeout after 30000ms
493
+ ```
494
+
495
+ **Causes:**
496
+ - Network connectivity issues
497
+ - Firewall blocking AWS API
498
+ - Proxy configuration needed
499
+
500
+ **Solutions:**
501
+
502
+ 1. **Check network connectivity:**
503
+ ```bash
504
+ curl -I https://api.pricing.us-east-1.amazonaws.com
505
+ ```
506
+
507
+ **Note:** This tests connectivity to the AWS Pricing API endpoint.
508
+
509
+ 2. **Configure proxy if needed:**
510
+ ```bash
511
+ export HTTP_PROXY=http://proxy.example.com:8080
512
+ export HTTPS_PROXY=http://proxy.example.com:8080
513
+ ```
514
+
515
+ 3. **Increase timeout (if using programmatically):**
516
+ ```typescript
517
+ const pricingClient = new PricingClient({
518
+ requestTimeout: 60000 // 60 seconds
519
+ });
520
+ ```
521
+
522
+ ## GitLab CI Common Issues
523
+
524
+ ### Error: Failed to post to GitLab
525
+
526
+ **Symptoms:**
527
+ ```
528
+ Warning: Failed to post to GitLab: 401 Unauthorized
529
+ ```
530
+
531
+ **Causes:**
532
+ - Missing or invalid GitLab token
533
+ - Insufficient token permissions
534
+ - Token not available in pipeline
535
+
536
+ **Solutions:**
537
+
538
+ 1. **Verify CI_JOB_TOKEN is available:**
539
+ ```yaml
540
+ cost-analysis:
541
+ script:
542
+ - echo "Token available: ${CI_JOB_TOKEN:+yes}"
543
+ - cdk-cost-analyzer ... --post-to-gitlab
544
+ ```
545
+
546
+ 2. **Enable API access for job tokens:**
547
+ - Go to **Settings > CI/CD > Token Access**
548
+ - Enable "Read/Write repository"
549
+
550
+ 3. **Use personal access token:**
551
+ ```yaml
552
+ cost-analysis:
553
+ variables:
554
+ GITLAB_TOKEN: $GITLAB_PERSONAL_TOKEN # Set in CI/CD variables
555
+ script:
556
+ - cdk-cost-analyzer ... --post-to-gitlab
557
+ ```
558
+
559
+ ### Error: Merge request IID not found
560
+
561
+ **Symptoms:**
562
+ ```
563
+ Error: CI_MERGE_REQUEST_IID not set
564
+ Cannot post to merge request
565
+ ```
566
+
567
+ **Causes:**
568
+ - Job not running in merge request context
569
+ - Pipeline triggered manually
570
+ - Incorrect job configuration
571
+
572
+ **Solutions:**
573
+
574
+ 1. **Ensure job runs only on merge requests:**
575
+ ```yaml
576
+ cost-analysis:
577
+ script:
578
+ - cdk-cost-analyzer ... --post-to-gitlab
579
+ only:
580
+ - merge_requests # Required for MR context
581
+ ```
582
+
583
+ 2. **Check pipeline source:**
584
+ ```yaml
585
+ cost-analysis:
586
+ script:
587
+ - |
588
+ if [ -z "$CI_MERGE_REQUEST_IID" ]; then
589
+ echo "Not a merge request pipeline, skipping GitLab post"
590
+ cdk-cost-analyzer ... --format text
591
+ else
592
+ cdk-cost-analyzer ... --post-to-gitlab
593
+ fi
594
+ ```
595
+
596
+ ### Error: Pipeline fails but no error message
597
+
598
+ **Symptoms:**
599
+ - Pipeline job fails
600
+ - No clear error in logs
601
+ - Exit code 1 or 2
602
+
603
+ **Causes:**
604
+ - Threshold exceeded (exit code 2)
605
+ - Silent failure
606
+ - Log truncation
607
+
608
+ **Solutions:**
609
+
610
+ 1. **Check exit code:**
611
+ ```yaml
612
+ cost-analysis:
613
+ script:
614
+ - cdk-cost-analyzer ... || EXIT_CODE=$?
615
+ - echo "Exit code: $EXIT_CODE"
616
+ - exit $EXIT_CODE
617
+ ```
618
+
619
+ 2. **Enable verbose logging:**
620
+ ```yaml
621
+ cost-analysis:
622
+ script:
623
+ - cdk-cost-analyzer ... --verbose
624
+ ```
625
+
626
+ 3. **Check for threshold violations:**
627
+ ```yaml
628
+ cost-analysis:
629
+ script:
630
+ - cdk-cost-analyzer ...
631
+ allow_failure:
632
+ exit_codes: [2] # Allow threshold violations
633
+ ```
634
+
635
+ ### Error: Cache not persisting between runs
636
+
637
+ **Symptoms:**
638
+ - Pricing API called every pipeline run
639
+ - No cache hits
640
+ - Slow analysis
641
+
642
+ **Causes:**
643
+ - Cache key changes every run
644
+ - Cache paths incorrect
645
+ - Cache not uploaded
646
+
647
+ **Solutions:**
648
+
649
+ 1. **Use stable cache key:**
650
+ ```yaml
651
+ cost-analysis:
652
+ cache:
653
+ key: pricing-cache # Stable key, not ${CI_COMMIT_REF_SLUG}
654
+ paths:
655
+ - .cdk-cost-analyzer-cache/
656
+ ```
657
+
658
+ 2. **Verify cache directory:**
659
+ ```yaml
660
+ cost-analysis:
661
+ script:
662
+ - ls -la .cdk-cost-analyzer-cache/ || echo "Cache empty"
663
+ - cdk-cost-analyzer ...
664
+ - ls -la .cdk-cost-analyzer-cache/
665
+ ```
666
+
667
+ 3. **Check cache policy:**
668
+ ```yaml
669
+ cost-analysis:
670
+ cache:
671
+ key: pricing-cache
672
+ paths:
673
+ - .cdk-cost-analyzer-cache/
674
+ policy: pull-push # Default, ensures upload
675
+ ```
676
+
677
+ ## Template Parsing Errors
678
+
679
+ ### Error: Invalid JSON/YAML template
680
+
681
+ **Symptoms:**
682
+ ```
683
+ Error: Failed to parse template
684
+ Unexpected token in JSON at position 123
685
+ ```
686
+
687
+ **Causes:**
688
+ - Malformed CloudFormation template
689
+ - Invalid JSON/YAML syntax
690
+ - Encoding issues
691
+
692
+ **Solutions:**
693
+
694
+ 1. **Validate template syntax:**
695
+ ```bash
696
+ # JSON
697
+ cat template.json | jq .
698
+
699
+ # YAML
700
+ npm install -g js-yaml
701
+ js-yaml template.yaml
702
+ ```
703
+
704
+ 2. **Check file encoding:**
705
+ ```bash
706
+ file template.json
707
+ # Should show: ASCII text or UTF-8 Unicode text
708
+ ```
709
+
710
+ 3. **Validate with AWS CLI:**
711
+ ```bash
712
+ aws cloudformation validate-template --template-body file://template.json --no-cli-pager
713
+ ```
714
+
715
+ ### Error: Template too large
716
+
717
+ **Symptoms:**
718
+ ```
719
+ Error: Template exceeds maximum size
720
+ ```
721
+
722
+ **Causes:**
723
+ - Template larger than 51,200 bytes
724
+ - Too many resources
725
+ - Large inline code
726
+
727
+ **Solutions:**
728
+
729
+ 1. **Split into multiple stacks:**
730
+ ```typescript
731
+ // Instead of one large stack
732
+ new NetworkStack(app, 'Network');
733
+ new ComputeStack(app, 'Compute');
734
+ new StorageStack(app, 'Storage');
735
+ ```
736
+
737
+ 2. **Use nested stacks:**
738
+ ```typescript
739
+ import * as cfn from 'aws-cdk-lib';
740
+
741
+ new cfn.NestedStack(this, 'NestedStack', {
742
+ // ...
743
+ });
744
+ ```
745
+
746
+ 3. **Move code to S3:**
747
+ ```typescript
748
+ // Instead of inline code
749
+ Code.fromInline('...')
750
+
751
+ // Use S3
752
+ Code.fromBucket(bucket, 'lambda.zip')
753
+ ```
754
+
755
+ ## Performance Issues
756
+
757
+ ### Issue: Analysis takes too long
758
+
759
+ **Symptoms:**
760
+ - Pipeline timeout
761
+ - Analysis takes >5 minutes
762
+ - Many API calls
763
+
764
+ **Solutions:**
765
+
766
+ 1. **Enable caching:**
767
+ ```yaml
768
+ cache:
769
+ enabled: true
770
+ durationHours: 24
771
+ ```
772
+
773
+ 2. **Exclude zero-cost resources:**
774
+ ```yaml
775
+ exclusions:
776
+ resourceTypes:
777
+ - AWS::IAM::Role
778
+ - AWS::IAM::Policy
779
+ - AWS::Logs::LogGroup
780
+ ```
781
+
782
+ 3. **Analyze only changed stacks:**
783
+ ```yaml
784
+ cost-analysis:
785
+ script:
786
+ - |
787
+ if git diff --name-only $CI_MERGE_REQUEST_DIFF_BASE_SHA | grep -q "infrastructure/stacks/compute"; then
788
+ cdk-cost-analyzer ... --stack ComputeStack
789
+ fi
790
+ ```
791
+
792
+ ### Issue: High memory usage
793
+
794
+ **Symptoms:**
795
+ - Out of memory errors
796
+ - Pipeline killed
797
+ - Node heap errors
798
+
799
+ **Solutions:**
800
+
801
+ 1. **Increase Node memory:**
802
+ ```yaml
803
+ cost-analysis:
804
+ variables:
805
+ NODE_OPTIONS: "--max-old-space-size=4096"
806
+ script:
807
+ - cdk-cost-analyzer ...
808
+ ```
809
+
810
+ 2. **Process stacks separately:**
811
+ ```yaml
812
+ cost-analysis:
813
+ parallel:
814
+ matrix:
815
+ - STACK: [Stack1, Stack2, Stack3]
816
+ script:
817
+ - cdk-cost-analyzer ... --stack $STACK
818
+ ```
819
+
820
+ ## Getting Help
821
+
822
+ If you encounter issues not covered in this guide:
823
+
824
+ 1. **Check existing issues:**
825
+ - Search GitLab issues for similar problems
826
+ - Review closed issues for solutions
827
+
828
+ 2. **Enable verbose logging:**
829
+ ```bash
830
+ cdk-cost-analyzer ... --verbose
831
+ ```
832
+
833
+ 3. **Collect diagnostic information:**
834
+ - CDK version: `npx cdk --version`
835
+ - Node version: `node --version`
836
+ - Tool version: `cdk-cost-analyzer --version`
837
+ - Configuration file (sanitized)
838
+ - Error messages and stack traces
839
+
840
+ 4. **Create an issue:**
841
+ - Include diagnostic information
842
+ - Provide minimal reproduction steps
843
+ - Sanitize sensitive information
844
+
845
+ 5. **Contact support:**
846
+ - Internal: ANWB DevOps team
847
+ - External: GitLab repository issues