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,85 @@
1
+ # Example CDK Cost Analyzer Configuration
2
+ # Place this file at the root of your project as .cdk-cost-analyzer.yml
3
+
4
+ # Cost thresholds for pipeline enforcement
5
+ thresholds:
6
+ # Default thresholds applied to all environments
7
+ default:
8
+ warning: 50 # USD per month - triggers warning but pipeline passes
9
+ error: 200 # USD per month - fails pipeline
10
+
11
+ # Environment-specific thresholds
12
+ environments:
13
+ production:
14
+ warning: 25 # Stricter thresholds for production changes
15
+ error: 100
16
+ staging:
17
+ warning: 50
18
+ error: 200
19
+ development:
20
+ warning: 100 # More lenient for development
21
+ error: 500
22
+
23
+ # Custom usage assumptions for cost estimation
24
+ # These override the default assumptions used by resource calculators
25
+ usageAssumptions:
26
+ # S3 bucket assumptions
27
+ s3:
28
+ storageGB: 500 # GB of standard storage per month
29
+ getRequests: 100000 # GET requests per month
30
+ putRequests: 10000 # PUT requests per month
31
+
32
+ # Lambda function assumptions
33
+ lambda:
34
+ invocationsPerMonth: 5000000 # Number of invocations per month
35
+ averageDurationMs: 500 # Average execution duration in milliseconds
36
+
37
+ # NAT Gateway assumptions
38
+ natGateway:
39
+ dataProcessedGB: 500 # GB of data processed per month
40
+
41
+ # Application Load Balancer assumptions
42
+ alb:
43
+ newConnectionsPerSecond: 50 # New TCP connections per second
44
+ activeConnectionsPerMinute: 5000 # Active TCP connections per minute
45
+ processedBytesGB: 1000 # GB processed per month
46
+
47
+ # Network Load Balancer assumptions
48
+ nlb:
49
+ newConnectionsPerSecond: 100 # New TCP/UDP connections per second
50
+ activeConnectionsPerMinute: 10000 # Active TCP/UDP connections per minute
51
+ processedBytesGB: 1000 # GB processed per month
52
+
53
+ # VPC Endpoint assumptions (for interface endpoints)
54
+ vpcEndpoint:
55
+ dataProcessedGB: 100 # GB of data processed per month
56
+
57
+ # API Gateway assumptions
58
+ apiGateway:
59
+ requestsPerMonth: 10000000 # API requests per month
60
+
61
+ # CDK synthesis configuration (for automatic synthesis)
62
+ synthesis:
63
+ appPath: ./infrastructure # Path to CDK application directory
64
+ outputPath: ./cdk.out # CDK output directory (default: cdk.out)
65
+ customCommand: npx cdk synth --all # Optional: custom synthesis command
66
+ context: # CDK context values passed to synthesis
67
+ environment: production
68
+ region: eu-central-1
69
+
70
+ # Resource types to exclude from cost analysis
71
+ # Useful for zero-cost or negligible-cost resources
72
+ exclusions:
73
+ resourceTypes:
74
+ - AWS::IAM::Role
75
+ - AWS::IAM::Policy
76
+ - AWS::IAM::User
77
+ - AWS::IAM::Group
78
+ - AWS::Logs::LogGroup
79
+ - AWS::CloudWatch::Alarm
80
+ - AWS::Events::Rule
81
+
82
+ # Pricing data cache configuration
83
+ cache:
84
+ enabled: true # Enable caching of AWS Pricing API data
85
+ durationHours: 24 # Cache duration in hours
@@ -0,0 +1,125 @@
1
+ # Example GitLab CI/CD Pipeline with CDK Cost Analysis
2
+ # Copy this to your project's .gitlab-ci.yml and customize as needed
3
+
4
+ stages:
5
+ - build
6
+ - test
7
+ - cost-analysis
8
+ - deploy
9
+
10
+ variables:
11
+ AWS_REGION: eu-central-1
12
+ CDK_APP_PATH: ./infrastructure
13
+
14
+ # Cache configuration for faster builds
15
+ .node-cache: &node-cache
16
+ cache:
17
+ key: ${CI_COMMIT_REF_SLUG}
18
+ paths:
19
+ - node_modules/
20
+ - ${CDK_APP_PATH}/node_modules/
21
+ - .cdk-cost-analyzer-cache/
22
+
23
+ # Install dependencies
24
+ install:
25
+ stage: build
26
+ image: node:18
27
+ <<: *node-cache
28
+ script:
29
+ - npm ci
30
+ - cd ${CDK_APP_PATH} && npm ci
31
+ artifacts:
32
+ paths:
33
+ - node_modules/
34
+ - ${CDK_APP_PATH}/node_modules/
35
+ expire_in: 1 hour
36
+
37
+ # Run unit tests
38
+ test:
39
+ stage: test
40
+ image: node:18
41
+ dependencies:
42
+ - install
43
+ script:
44
+ - npm test
45
+ - cd ${CDK_APP_PATH} && npm test
46
+
47
+ # Synthesize CDK application
48
+ synthesize:
49
+ stage: test
50
+ image: node:18
51
+ dependencies:
52
+ - install
53
+ script:
54
+ - cd ${CDK_APP_PATH}
55
+ - npx cdk synth --all
56
+ artifacts:
57
+ paths:
58
+ - ${CDK_APP_PATH}/cdk.out
59
+ expire_in: 1 hour
60
+ only:
61
+ changes:
62
+ - infrastructure/**/*
63
+
64
+ # Cost analysis for merge requests
65
+ cost-analysis:
66
+ stage: cost-analysis
67
+ image: node:18
68
+ dependencies:
69
+ - install
70
+ <<: *node-cache
71
+ before_script:
72
+ # Install CDK Cost Analyzer globally
73
+ - npm install -g cdk-cost-analyzer
74
+ script:
75
+ # Run cost analysis with automatic synthesis
76
+ - |
77
+ cdk-cost-analyzer pipeline \
78
+ --synth \
79
+ --cdk-app-path ${CDK_APP_PATH} \
80
+ --region ${AWS_REGION} \
81
+ --config .cdk-cost-analyzer.yml \
82
+ --environment ${CI_ENVIRONMENT_NAME:-development} \
83
+ --format markdown \
84
+ --post-to-gitlab
85
+ # Allow pipeline to pass even if error threshold is exceeded
86
+ # Remove this to strictly enforce thresholds
87
+ allow_failure:
88
+ exit_codes: [2]
89
+ only:
90
+ - merge_requests
91
+ only:
92
+ changes:
93
+ - infrastructure/**/*
94
+ - .cdk-cost-analyzer.yml
95
+
96
+ # Deploy to staging
97
+ deploy:staging:
98
+ stage: deploy
99
+ image: node:18
100
+ dependencies:
101
+ - install
102
+ - synthesize
103
+ script:
104
+ - cd ${CDK_APP_PATH}
105
+ - npx cdk deploy --all --require-approval never
106
+ environment:
107
+ name: staging
108
+ only:
109
+ - develop
110
+
111
+ # Deploy to production (manual approval required)
112
+ deploy:production:
113
+ stage: deploy
114
+ image: node:18
115
+ dependencies:
116
+ - install
117
+ - synthesize
118
+ script:
119
+ - cd ${CDK_APP_PATH}
120
+ - npx cdk deploy --all --require-approval never
121
+ environment:
122
+ name: production
123
+ only:
124
+ - main
125
+ when: manual
@@ -0,0 +1,26 @@
1
+ // api-usage.js - Example of programmatic API usage
2
+ const { analyzeCosts } = require('../dist/api');
3
+ const fs = require('fs');
4
+
5
+ async function test() {
6
+ const baseTemplate = fs.readFileSync('./simple/base.json', 'utf-8');
7
+ const targetTemplate = fs.readFileSync('./simple/target.json', 'utf-8');
8
+
9
+ const result = await analyzeCosts({
10
+ baseTemplate,
11
+ targetTemplate,
12
+ region: 'eu-central-1'
13
+ });
14
+
15
+ console.log('Total Delta:', result.totalDelta);
16
+ console.log('Currency:', result.currency);
17
+ console.log('Added Resources:', result.addedResources.length);
18
+ console.log('Removed Resources:', result.removedResources.length);
19
+ console.log('Modified Resources:', result.modifiedResources.length);
20
+ console.log('\nAdded Resources Details:');
21
+ result.addedResources.forEach(r => {
22
+ console.log(` - ${r.logicalId} (${r.type}): ${r.monthlyCost.currency} ${r.monthlyCost.amount.toFixed(2)} [${r.monthlyCost.confidence}]`);
23
+ });
24
+ }
25
+
26
+ test().catch(console.error);
@@ -0,0 +1,16 @@
1
+ {
2
+ "Resources": {
3
+ "MyBucket": {
4
+ "Type": "AWS::S3::Bucket",
5
+ "Properties": {}
6
+ },
7
+ "MyFunction": {
8
+ "Type": "AWS::Lambda::Function",
9
+ "Properties": {
10
+ "Runtime": "nodejs18.x",
11
+ "Handler": "index.handler",
12
+ "MemorySize": 128
13
+ }
14
+ }
15
+ }
16
+ }
@@ -0,0 +1,29 @@
1
+ {
2
+ "Resources": {
3
+ "MyBucket": {
4
+ "Type": "AWS::S3::Bucket",
5
+ "Properties": {}
6
+ },
7
+ "MyFunction": {
8
+ "Type": "AWS::Lambda::Function",
9
+ "Properties": {
10
+ "Runtime": "nodejs18.x",
11
+ "Handler": "index.handler",
12
+ "MemorySize": 512
13
+ }
14
+ },
15
+ "MyInstance": {
16
+ "Type": "AWS::EC2::Instance",
17
+ "Properties": {
18
+ "InstanceType": "t3.medium"
19
+ }
20
+ },
21
+ "MyDatabase": {
22
+ "Type": "AWS::RDS::DBInstance",
23
+ "Properties": {
24
+ "DBInstanceClass": "db.t3.micro",
25
+ "Engine": "postgres"
26
+ }
27
+ }
28
+ }
29
+ }
@@ -0,0 +1,251 @@
1
+ # GitLab CI/CD Pipeline for Monorepo with Parallel CDK Cost Analysis
2
+ # This pipeline runs cost analysis in parallel for multiple CDK applications
3
+
4
+ stages:
5
+ - build
6
+ - test
7
+ - cost-analysis
8
+ - deploy
9
+
10
+ variables:
11
+ AWS_REGION: us-east-1
12
+ NODE_VERSION: "18"
13
+
14
+ # Install dependencies for all packages in the workspace
15
+ build:
16
+ stage: build
17
+ image: node:${NODE_VERSION}
18
+ script:
19
+ - echo "Installing dependencies for all packages..."
20
+ - npm ci
21
+ cache:
22
+ key: ${CI_COMMIT_REF_SLUG}
23
+ paths:
24
+ - node_modules/
25
+ - packages/*/node_modules/
26
+ artifacts:
27
+ paths:
28
+ - node_modules/
29
+ - packages/*/node_modules/
30
+ expire_in: 1 hour
31
+
32
+ # Run tests for all packages in parallel
33
+ test:frontend:
34
+ stage: test
35
+ image: node:${NODE_VERSION}
36
+ dependencies:
37
+ - build
38
+ script:
39
+ - cd packages/frontend-infra
40
+ - npm test
41
+ only:
42
+ - merge_requests
43
+ - main
44
+
45
+ test:backend:
46
+ stage: test
47
+ image: node:${NODE_VERSION}
48
+ dependencies:
49
+ - build
50
+ script:
51
+ - cd packages/backend-infra
52
+ - npm test
53
+ only:
54
+ - merge_requests
55
+ - main
56
+
57
+ test:data:
58
+ stage: test
59
+ image: node:${NODE_VERSION}
60
+ dependencies:
61
+ - build
62
+ script:
63
+ - cd packages/data-infra
64
+ - npm test
65
+ only:
66
+ - merge_requests
67
+ - main
68
+
69
+ # Analyze cost changes for frontend infrastructure
70
+ cost-analysis:frontend:
71
+ stage: cost-analysis
72
+ image: node:${NODE_VERSION}
73
+ dependencies:
74
+ - build
75
+ before_script:
76
+ - npm install -g cdk-cost-analyzer
77
+ - |
78
+ if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
79
+ echo "ERROR: AWS credentials not configured"
80
+ exit 1
81
+ fi
82
+ script:
83
+ - echo "Analyzing frontend infrastructure cost changes..."
84
+ - cd packages/frontend-infra
85
+ - |
86
+ cdk-cost-analyzer pipeline \
87
+ --base-branch ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} \
88
+ --target-branch ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} \
89
+ --cdk-app-path . \
90
+ --region ${AWS_REGION} \
91
+ --format markdown \
92
+ --post-to-gitlab
93
+ cache:
94
+ key: pricing-cache-frontend
95
+ paths:
96
+ - .cdk-cost-analyzer-cache/
97
+ artifacts:
98
+ paths:
99
+ - packages/frontend-infra/cost-report.md
100
+ expire_in: 30 days
101
+ only:
102
+ - merge_requests
103
+ allow_failure: false
104
+
105
+ # Analyze cost changes for backend infrastructure
106
+ cost-analysis:backend:
107
+ stage: cost-analysis
108
+ image: node:${NODE_VERSION}
109
+ dependencies:
110
+ - build
111
+ before_script:
112
+ - npm install -g cdk-cost-analyzer
113
+ - |
114
+ if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
115
+ echo "ERROR: AWS credentials not configured"
116
+ exit 1
117
+ fi
118
+ script:
119
+ - echo "Analyzing backend infrastructure cost changes..."
120
+ - cd packages/backend-infra
121
+ - |
122
+ cdk-cost-analyzer pipeline \
123
+ --base-branch ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} \
124
+ --target-branch ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} \
125
+ --cdk-app-path . \
126
+ --region ${AWS_REGION} \
127
+ --format markdown \
128
+ --post-to-gitlab
129
+ cache:
130
+ key: pricing-cache-backend
131
+ paths:
132
+ - .cdk-cost-analyzer-cache/
133
+ artifacts:
134
+ paths:
135
+ - packages/backend-infra/cost-report.md
136
+ expire_in: 30 days
137
+ only:
138
+ - merge_requests
139
+ allow_failure: false
140
+
141
+ # Analyze cost changes for data infrastructure
142
+ cost-analysis:data:
143
+ stage: cost-analysis
144
+ image: node:${NODE_VERSION}
145
+ dependencies:
146
+ - build
147
+ before_script:
148
+ - npm install -g cdk-cost-analyzer
149
+ - |
150
+ if [ -z "$AWS_ACCESS_KEY_ID" ] || [ -z "$AWS_SECRET_ACCESS_KEY" ]; then
151
+ echo "ERROR: AWS credentials not configured"
152
+ exit 1
153
+ fi
154
+ script:
155
+ - echo "Analyzing data infrastructure cost changes..."
156
+ - cd packages/data-infra
157
+ - |
158
+ cdk-cost-analyzer pipeline \
159
+ --base-branch ${CI_MERGE_REQUEST_TARGET_BRANCH_NAME} \
160
+ --target-branch ${CI_MERGE_REQUEST_SOURCE_BRANCH_NAME} \
161
+ --cdk-app-path . \
162
+ --region ${AWS_REGION} \
163
+ --format markdown \
164
+ --post-to-gitlab
165
+ cache:
166
+ key: pricing-cache-data
167
+ paths:
168
+ - .cdk-cost-analyzer-cache/
169
+ artifacts:
170
+ paths:
171
+ - packages/data-infra/cost-report.md
172
+ expire_in: 30 days
173
+ only:
174
+ - merge_requests
175
+ allow_failure: false
176
+
177
+ # Deploy frontend infrastructure
178
+ deploy:frontend:
179
+ stage: deploy
180
+ image: node:${NODE_VERSION}
181
+ dependencies:
182
+ - build
183
+ before_script:
184
+ - npm install -g aws-cdk
185
+ script:
186
+ - cd packages/frontend-infra
187
+ - echo "Deploying frontend infrastructure..."
188
+ - cdk deploy --require-approval never
189
+ only:
190
+ - main
191
+ when: manual
192
+ environment:
193
+ name: production/frontend
194
+ action: start
195
+
196
+ # Deploy backend infrastructure
197
+ deploy:backend:
198
+ stage: deploy
199
+ image: node:${NODE_VERSION}
200
+ dependencies:
201
+ - build
202
+ before_script:
203
+ - npm install -g aws-cdk
204
+ script:
205
+ - cd packages/backend-infra
206
+ - echo "Deploying backend infrastructure..."
207
+ - cdk deploy --require-approval never
208
+ only:
209
+ - main
210
+ when: manual
211
+ environment:
212
+ name: production/backend
213
+ action: start
214
+
215
+ # Deploy data infrastructure
216
+ deploy:data:
217
+ stage: deploy
218
+ image: node:${NODE_VERSION}
219
+ dependencies:
220
+ - build
221
+ before_script:
222
+ - npm install -g aws-cdk
223
+ script:
224
+ - cd packages/data-infra
225
+ - echo "Deploying data infrastructure..."
226
+ - cdk deploy --require-approval never
227
+ only:
228
+ - main
229
+ when: manual
230
+ environment:
231
+ name: production/data
232
+ action: start
233
+
234
+ # Optional: Deploy all to development environment
235
+ deploy:dev:all:
236
+ stage: deploy
237
+ image: node:${NODE_VERSION}
238
+ dependencies:
239
+ - build
240
+ before_script:
241
+ - npm install -g aws-cdk
242
+ script:
243
+ - echo "Deploying all infrastructure to development..."
244
+ - cd packages/frontend-infra && cdk deploy --require-approval never
245
+ - cd ../backend-infra && cdk deploy --require-approval never
246
+ - cd ../data-infra && cdk deploy --require-approval never
247
+ only:
248
+ - develop
249
+ environment:
250
+ name: development
251
+ action: start