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.
- package/.cdk-cost-analyzer-cache/metadata.json +12 -0
- package/.gitlab-ci.yml +214 -0
- package/.husky/pre-commit +12 -0
- package/.kiro/hooks/accessibility-audit.kiro.hook +18 -0
- package/.kiro/hooks/api-schema-validation.kiro.hook +21 -0
- package/.kiro/hooks/auto-test-on-save.kiro.hook +19 -0
- package/.kiro/hooks/cdk-synth-on-change.kiro.hook +20 -0
- package/.kiro/hooks/code-coverage-check.kiro.hook +14 -0
- package/.kiro/hooks/commit-message-helper.kiro.hook +14 -0
- package/.kiro/hooks/dependency-update-check.kiro.hook +14 -0
- package/.kiro/hooks/env-file-validation.kiro.hook +18 -0
- package/.kiro/hooks/lint-and-format-on-save.kiro.hook +21 -0
- package/.kiro/hooks/mcp-config-validation.kiro.hook +17 -0
- package/.kiro/hooks/mcp-server-test.kiro.hook +14 -0
- package/.kiro/hooks/performance-analysis.kiro.hook +14 -0
- package/.kiro/hooks/readme-spell-check.kiro.hook +14 -0
- package/.kiro/hooks/security-scan-on-dependency-change.kiro.hook +21 -0
- package/.kiro/hooks/translation-update.kiro.hook +18 -0
- package/.kiro/hooks/update-documentation.kiro.hook +18 -0
- package/.kiro/settings/mcp.json +20 -0
- package/.kiro/specs/cdk-cost-analyzer/design.md +620 -0
- package/.kiro/specs/cdk-cost-analyzer/requirements.md +183 -0
- package/.kiro/specs/cdk-cost-analyzer/tasks.md +357 -0
- package/.kiro/specs/github-actions-ci/design.md +281 -0
- package/.kiro/specs/github-actions-ci/requirements.md +86 -0
- package/.kiro/specs/github-actions-ci/tasks.md +115 -0
- package/.kiro/specs/nlb-calculator-test-coverage/design.md +190 -0
- package/.kiro/specs/nlb-calculator-test-coverage/requirements.md +84 -0
- package/.kiro/specs/nlb-calculator-test-coverage/tasks.md +150 -0
- package/.kiro/specs/production-readiness/design.md +1213 -0
- package/.kiro/specs/production-readiness/requirements.md +312 -0
- package/.kiro/specs/production-readiness/tasks.md +269 -0
- package/.kiro/specs/repository-cleanup/design.md +283 -0
- package/.kiro/specs/repository-cleanup/requirements.md +74 -0
- package/.kiro/specs/repository-cleanup/tasks.md +64 -0
- package/.kiro/steering/aws-cli-best-practices.md +41 -0
- package/.kiro/steering/cdk-best-practices.md +49 -0
- package/.kiro/steering/development-standards.md +54 -0
- package/.kiro/steering/docker-best-practices.md +34 -0
- package/.kiro/steering/documentation-style.md +151 -0
- package/.kiro/steering/git-best-practices.md +37 -0
- package/.kiro/steering/mcp-best-practices.md +95 -0
- package/.kiro/steering/python-best-practices.md +48 -0
- package/.kiro/steering/react-best-practices.md +44 -0
- package/.kiro/steering/security-best-practices.md +41 -0
- package/.kiro/steering/testing-best-practices.md +59 -0
- package/.kiro/steering/typescript-best-practices.md +40 -0
- package/CHANGELOG.md +49 -0
- package/CONTRIBUTING.md +258 -0
- package/LICENSE +19 -0
- package/README.md +480 -0
- package/SECURITY.md +117 -0
- package/dist/api/index.d.ts +11 -0
- package/dist/api/index.js +65 -0
- package/dist/api/types.d.ts +15 -0
- package/dist/api/types.js +3 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +262 -0
- package/dist/config/ConfigManager.d.ts +40 -0
- package/dist/config/ConfigManager.js +238 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +19 -0
- package/dist/config/types.d.ts +72 -0
- package/dist/config/types.js +15 -0
- package/dist/diff/DiffEngine.d.ts +7 -0
- package/dist/diff/DiffEngine.js +73 -0
- package/dist/diff/index.d.ts +2 -0
- package/dist/diff/index.js +21 -0
- package/dist/diff/types.d.ts +20 -0
- package/dist/diff/types.js +3 -0
- package/dist/integrations/GitLabIntegration.d.ts +7 -0
- package/dist/integrations/GitLabIntegration.js +45 -0
- package/dist/integrations/index.d.ts +2 -0
- package/dist/integrations/index.js +21 -0
- package/dist/integrations/types.d.ts +11 -0
- package/dist/integrations/types.js +13 -0
- package/dist/parser/TemplateParser.d.ts +8 -0
- package/dist/parser/TemplateParser.js +75 -0
- package/dist/parser/index.d.ts +2 -0
- package/dist/parser/index.js +22 -0
- package/dist/parser/types.d.ts +30 -0
- package/dist/parser/types.js +3 -0
- package/dist/pipeline/PipelineOrchestrator.d.ts +23 -0
- package/dist/pipeline/PipelineOrchestrator.js +191 -0
- package/dist/pipeline/index.d.ts +2 -0
- package/dist/pipeline/index.js +19 -0
- package/dist/pipeline/types.d.ts +41 -0
- package/dist/pipeline/types.js +13 -0
- package/dist/pricing/CacheManager.d.ts +75 -0
- package/dist/pricing/CacheManager.js +195 -0
- package/dist/pricing/PricingClient.d.ts +17 -0
- package/dist/pricing/PricingClient.js +122 -0
- package/dist/pricing/PricingService.d.ts +16 -0
- package/dist/pricing/PricingService.js +149 -0
- package/dist/pricing/calculators/ALBCalculator.d.ts +16 -0
- package/dist/pricing/calculators/ALBCalculator.js +163 -0
- package/dist/pricing/calculators/APIGatewayCalculator.d.ts +10 -0
- package/dist/pricing/calculators/APIGatewayCalculator.js +177 -0
- package/dist/pricing/calculators/CloudFrontCalculator.d.ts +59 -0
- package/dist/pricing/calculators/CloudFrontCalculator.js +151 -0
- package/dist/pricing/calculators/DynamoDBCalculator.d.ts +9 -0
- package/dist/pricing/calculators/DynamoDBCalculator.js +146 -0
- package/dist/pricing/calculators/EC2Calculator.d.ts +7 -0
- package/dist/pricing/calculators/EC2Calculator.js +80 -0
- package/dist/pricing/calculators/ECSCalculator.d.ts +9 -0
- package/dist/pricing/calculators/ECSCalculator.js +116 -0
- package/dist/pricing/calculators/ElastiCacheCalculator.d.ts +8 -0
- package/dist/pricing/calculators/ElastiCacheCalculator.js +106 -0
- package/dist/pricing/calculators/LambdaCalculator.d.ts +13 -0
- package/dist/pricing/calculators/LambdaCalculator.js +111 -0
- package/dist/pricing/calculators/NLBCalculator.d.ts +16 -0
- package/dist/pricing/calculators/NLBCalculator.js +138 -0
- package/dist/pricing/calculators/NatGatewayCalculator.d.ts +12 -0
- package/dist/pricing/calculators/NatGatewayCalculator.js +116 -0
- package/dist/pricing/calculators/RDSCalculator.d.ts +9 -0
- package/dist/pricing/calculators/RDSCalculator.js +103 -0
- package/dist/pricing/calculators/S3Calculator.d.ts +8 -0
- package/dist/pricing/calculators/S3Calculator.js +68 -0
- package/dist/pricing/calculators/VPCEndpointCalculator.d.ts +12 -0
- package/dist/pricing/calculators/VPCEndpointCalculator.js +129 -0
- package/dist/pricing/index.d.ts +10 -0
- package/dist/pricing/index.js +37 -0
- package/dist/pricing/types.d.ts +53 -0
- package/dist/pricing/types.js +22 -0
- package/dist/releasetag.txt +1 -0
- package/dist/reporter/Reporter.d.ts +18 -0
- package/dist/reporter/Reporter.js +412 -0
- package/dist/reporter/index.d.ts +2 -0
- package/dist/reporter/index.js +21 -0
- package/dist/reporter/types.d.ts +72 -0
- package/dist/reporter/types.js +3 -0
- package/dist/synthesis/SynthesisOrchestrator.d.ts +26 -0
- package/dist/synthesis/SynthesisOrchestrator.js +243 -0
- package/dist/synthesis/index.d.ts +2 -0
- package/dist/synthesis/index.js +19 -0
- package/dist/synthesis/types.d.ts +17 -0
- package/dist/synthesis/types.js +13 -0
- package/dist/threshold/ThresholdEnforcer.d.ts +29 -0
- package/dist/threshold/ThresholdEnforcer.js +143 -0
- package/dist/threshold/index.d.ts +2 -0
- package/dist/threshold/index.js +19 -0
- package/dist/threshold/types.d.ts +15 -0
- package/dist/threshold/types.js +17 -0
- package/docs/CALCULATORS.md +820 -0
- package/docs/CI_CD.md +608 -0
- package/docs/CONFIGURATION.md +407 -0
- package/docs/DEVELOPMENT.md +387 -0
- package/docs/RELEASE.md +223 -0
- package/docs/TROUBLESHOOTING.md +847 -0
- package/examples/.cdk-cost-analyzer.yml +85 -0
- package/examples/.gitlab-ci.yml +125 -0
- package/examples/api-usage.js +26 -0
- package/examples/complex/base.json +16 -0
- package/examples/complex/target.json +29 -0
- package/examples/monorepo/.gitlab-ci.yml +251 -0
- package/examples/monorepo/README.md +341 -0
- package/examples/monorepo/package.json +27 -0
- package/examples/monorepo/packages/backend-infra/.cdk-cost-analyzer.yml +34 -0
- package/examples/monorepo/packages/backend-infra/bin/app.ts +16 -0
- package/examples/monorepo/packages/backend-infra/cdk.json +7 -0
- package/examples/monorepo/packages/backend-infra/lib/backend-stack.ts +128 -0
- package/examples/monorepo/packages/backend-infra/package.json +30 -0
- package/examples/monorepo/packages/backend-infra/tsconfig.json +11 -0
- package/examples/monorepo/packages/data-infra/.cdk-cost-analyzer.yml +38 -0
- package/examples/monorepo/packages/data-infra/bin/app.ts +16 -0
- package/examples/monorepo/packages/data-infra/cdk.json +7 -0
- package/examples/monorepo/packages/data-infra/lib/data-stack.ts +121 -0
- package/examples/monorepo/packages/data-infra/package.json +30 -0
- package/examples/monorepo/packages/data-infra/tsconfig.json +11 -0
- package/examples/monorepo/packages/frontend-infra/.cdk-cost-analyzer.yml +31 -0
- package/examples/monorepo/packages/frontend-infra/bin/app.ts +16 -0
- package/examples/monorepo/packages/frontend-infra/cdk.json +7 -0
- package/examples/monorepo/packages/frontend-infra/lib/frontend-stack.ts +60 -0
- package/examples/monorepo/packages/frontend-infra/package.json +30 -0
- package/examples/monorepo/packages/frontend-infra/tsconfig.json +11 -0
- package/examples/monorepo/tsconfig.json +35 -0
- package/examples/multi-stack/.cdk-cost-analyzer.yml +72 -0
- package/examples/multi-stack/.gitlab-ci.yml +184 -0
- package/examples/multi-stack/README.md +279 -0
- package/examples/multi-stack/bin/app.ts +36 -0
- package/examples/multi-stack/cdk.json +72 -0
- package/examples/multi-stack/lib/compute-stack.ts +128 -0
- package/examples/multi-stack/lib/networking-stack.ts +69 -0
- package/examples/multi-stack/lib/storage-stack.ts +141 -0
- package/examples/multi-stack/package-lock.json +4437 -0
- package/examples/multi-stack/package.json +42 -0
- package/examples/multi-stack/tsconfig.json +34 -0
- package/examples/simple/base.json +8 -0
- package/examples/simple/target.json +14 -0
- package/examples/single-stack/.NVP +0 -0
- package/examples/single-stack/.cdk-cost-analyzer.yml +52 -0
- package/examples/single-stack/.gitlab-ci.yml +126 -0
- package/examples/single-stack/README.md +184 -0
- package/examples/single-stack/UeK +0 -0
- package/examples/single-stack/bin/app.ts +16 -0
- package/examples/single-stack/cdk.json +72 -0
- package/examples/single-stack/lib/infrastructure-stack.ts +119 -0
- package/examples/single-stack/package-lock.json +4443 -0
- package/examples/single-stack/package.json +38 -0
- package/examples/single-stack/tsconfig.json +34 -0
- package/package.json +139 -0
- package/test-cdk-project/README-COMPUTE.md +141 -0
- package/test-cdk-project/README.md +95 -0
- package/test-cdk-project/app-with-compute.js +102 -0
- package/test-cdk-project/app.js +81 -0
- package/test-cdk-project/cdk-compute.json +3 -0
- package/test-cdk-project/cdk.context.json +7 -0
- package/test-cdk-project/cdk.json +3 -0
- package/test-cdk-project/cdk.out/TestStack.assets.json +21 -0
- package/test-cdk-project/cdk.out/TestStack.template.json +115 -0
- package/test-cdk-project/cdk.out/cdk.out +1 -0
- package/test-cdk-project/cdk.out/manifest.json +503 -0
- package/test-cdk-project/cdk.out/tree.json +1 -0
- package/test-cdk-project/cdk.out.base/TestStack.assets.json +21 -0
- package/test-cdk-project/cdk.out.base/TestStack.template.json +115 -0
- package/test-cdk-project/cdk.out.base/cdk.out +1 -0
- package/test-cdk-project/cdk.out.base/manifest.json +503 -0
- package/test-cdk-project/cdk.out.base/tree.json +1 -0
- package/test-cdk-project/cdk.out.target/TestStack.assets.json +21 -0
- package/test-cdk-project/cdk.out.target/TestStack.template.json +183 -0
- package/test-cdk-project/cdk.out.target/cdk.out +1 -0
- package/test-cdk-project/cdk.out.target/manifest.json +521 -0
- package/test-cdk-project/cdk.out.target/tree.json +1 -0
- package/test-cdk-project/package-lock.json +422 -0
- package/test-cdk-project/package.json +17 -0
- package/tools/workflows/README.md +102 -0
- package/tools/workflows/validate-workflows.js +109 -0
- 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
|
+
[](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/)
|