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
|
@@ -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
|