dil-costlens
v0.1.0
Published
Estimate & Optimize AWS CDK Costs before you deploy.
Downloads
6
Readme
CostLens-CDK
Estimate & Optimize AWS CDK Costs before you deploy.
Overview
CostLens-CDK is a developer-first tool to estimate monthly AWS costs for your CDK stacks before deployment. It synthesizes your CDK app, parses the resulting CloudFormation, estimates monthly costs for all major AWS resources, and provides LLM-powered insights. Supports CLI, CI, and PR comments.
Features
- Supports all major AWS cost resources: EC2, EBS, RDS, Lambda, S3, DynamoDB, ElastiCache, API Gateway, ALB/NLB, NAT Gateway, CloudWatch, ECR, Data Transfer, and more.
- Live AWS Pricing API integration with fallback to a local catalog for robust, up-to-date pricing.
- Assumptions file for usage overrides and scenario modeling.
- LLM-powered insights (local heuristics + Bedrock integration).
- Beautiful CLI output and CI/PR integration.
Quick Start
1. Install dependencies
npm install2. Build all packages
npx tsc --build3. Synthesize your CDK app
cdk synth > cdk.out/template.json4. Run CostLens-CDK (from built output)
node dist/cli/src/index.js analyze --region us-west-2 --format table5. Output
- Beautiful colorized table in the terminal
- Optional JSON output for CI/automation
- LLM-powered risk and optimization insights
CLI Usage
npx costlens analyze [options]Options:
--region <region>: AWS region (default: us-east-1)--assumptions <file>: Path to assumptions file (YAML/JSON)--format <fmt>: Output format (table,json, or both)--out <file>: Write JSON output to file--no-free-tier: Ignore AWS free tier--ci: CI mode (for GitHub Actions, etc)
Assumptions File
Override usage patterns for more accurate estimates. Example:
Lambda:
MyFunction:
monthlyInvocations: 10000000
avgMsPerInvoke: 250
S3:
MyBucket:
storageGb: 500
monthlyPutRequests: 100000LLM Insights
- Local heuristics flag risky or high-cost resources
- Optionally integrates with Amazon Bedrock for advanced analysis
- To enable Bedrock LLM-powered insights, set the environment variable
BEDROCK_LLM=1when running the CLI:
env BEDROCK_LLM=1 aws-vault exec dil-team-hackfest -- node dist/cli/src/index.js analyze --region us-west-2 --format tableIf BEDROCK_LLM is not set, only local heuristics will be used for insights.
CI/CD Integration
- GitHub Actions workflow included for PR cost comments
- Example:
.github/workflows/costlens-pr.yml
Extending the Catalog
- See
packages/pricing/src/catalog.jsonfor fallback prices - Add more regions, instance types, or custom pricing as needed
Monorepo Structure
packages/core: IR types, parser, estimatorpackages/pricing: Pricing engine (AWS API + catalog)packages/reporter: CLI table and JSON outputpackages/cli: CLI entrypointpackages/llm: LLM/risk analysis
Contributing
Pull requests welcome! Please add tests and update documentation as needed.
License
Diligent
