{"version":"1.0","url":"https://imperfectblog.vercel.app/blog/ai-infrastructure-cost-cli","title":"I Built a CLI to Show Me What My AI-Generated Infrastructure Actually Costs","description":"AI tools generate working infrastructure fast, but cost stays invisible until the bill arrives. I built Slate to fix that — a CLI that reads your CDK output and shows real prices before you deploy.","publishedAt":"2026-05-14","updatedAt":null,"author":{"name":"Paul Kinyatti","bio":"Building things, writing about them."},"tags":["devtools","aws","infrastructure","ai"],"category":"engineering","readTime":4,"wordCount":862,"coverImage":{"url":"https://images.unsplash.com/photo-1551288049-bebda4e38f71?w=1200&h=675&fit=crop","alt":"Dashboard showing cloud infrastructure cost metrics","caption":null},"content":{"raw":"\nLast month I asked an AI assistant to set up a VPC with a private subnet for my side project. It did exactly what I asked — clean CDK code, proper security groups, everything synthesized on the first try. What it didn't mention was the NAT Gateway it added to route traffic from the private subnet. That's $32.85/month for a project with twelve users. I found out when the bill arrived.\n\nThat moment — staring at a line item I never consciously chose — is what led me to build Slate.\n\n## The Problem\n\nAI tools write infrastructure code fast. You describe what you want, you get working CDK or Terraform, you deploy. Going from \"I need a database\" to a running RDS instance takes minutes now. But you still find out what things cost the same way you always did: when the bill shows up.\n\nThe issue isn't that AI generates expensive infrastructure. It's that cost is invisible when you're making the decision. A few examples I've hit:\n\n- A NAT Gateway for private subnet internet access: **$32.85/month**. Fixed cost — same whether you have zero users or ten thousand.\n- Multi-AZ RDS enabled by default on a side project: doubles the database cost from **$15.33/month to $30.66/month** for redundancy you don't need yet.\n- DynamoDB provisioned mode instead of on-demand for a table handling 50 requests/day: you're paying for unused capacity.\n\nNone of these are wrong in the right context. But they should be conscious choices, not surprises.\n\n## What Slate Does\n\nSlate reads your `cdk.out` directory, classifies every resource as fixed or variable cost, and shows you a cost estimate broken down by user growth tiers. It uses a mix of known prices for common resources and the AWS Price List API for others.\n\n```bash\nnpx cdk synth\nnpx slate estimate\n```\n\nOutput:\n\n```\n╔══════════════════════════════════════════════╗\n║  Slate  │  Region: us-east-1  │  CDK         ║\n╠══════════════════════════════════════════════╣\n║  FIXED COSTS                                 ║\n║  RDS db.t3.micro             $15.33/mo       ║\n║  NAT Gateway (1)             $32.85/mo       ║\n╠══════════════════════════════════════════════╣\n║  Users        Variable    Total              ║\n║  0 – 100      $0 ✦        $48 /mo            ║\n║  100 – 1k     $2 – $18    $50 – $66 /mo      ║\n║  1k – 10k     $18 – $155  $66 – $203 /mo     ║\n║  10k – 100k   $155 – $1.4k $203 – $1.4k /mo  ║\n║  100k – 1M    $1.4k – $12k $1.4k – $12k /mo  ║\n╚══════════════════════════════════════════════╝\n```\n\nThe ✦ means free tier applies. At low usage, Lambda and DynamoDB cost nothing — Slate accounts for that instead of assuming every request costs money from day one.\n\n## Fixed vs Variable\n\nEvery resource is either fixed or variable. Fixed resources cost the same regardless of traffic: an RDS instance, a NAT Gateway, an EKS control plane. Variable resources scale with usage: Lambda invocations, API Gateway requests, DynamoDB reads/writes, S3 storage.\n\nFixed costs are your floor — you pay them the moment you deploy. Variable costs grow with users. Slate classifies every resource in your CloudFormation template and models costs across five tiers from 0 to 1 million users.\n\nThis lets you answer: \"What does this cost with no users? What about at 10k? Where does cost start climbing?\"\n\n## Narrowing the Estimate\n\nSlate generates a `cost-profile.yaml` with fields for every variable resource it finds. You don't have to fill it in — leave it empty and variable costs show as a range. Fill in what you know and those fields become exact.\n\n```yaml\ntraffic_profile:\n  lambda:\n    invocations_per_user_per_month: 120\n    avg_duration_ms: 250\n  api_gateway:\n    calls_per_user_per_month: 200\n  dynamodb:\n    reads_per_user_per_month: 500\n    writes_per_user_per_month: 80\n```\n\nMore input narrows the estimate. You can run `npx slate wizard` for a guided walkthrough or edit the YAML directly. Either way, the next estimate run uses whatever you've provided.\n\n## Cost Drift Detection\n\nSlate saves a report after each run. On the next run, it diffs against the previous report and shows what changed:\n\n```\nCOST DRIFT:\n+ NAT Gateway +$32.85/mo (fixed)\n1k–10k: $171/mo → $203/mo (+$32/mo)\n```\n\nIn CI, you set a budget threshold. If the estimate exceeds it, Slate exits with code 1 and your pipeline fails. The GitHub Actions workflow posts the cost table as a PR comment so reviewers see cost impact before merging.\n\nCost becomes visible on every PR that touches infrastructure — not a surprise on next month's bill.\n\n## Watch Mode\n\nSlate has a `--watch` flag that monitors your `cdk.out` directory and re-estimates automatically as you iterate on your CDK code. You change a resource, re-synth, and the cost table updates without running the command again.\n\n```bash\nnpx slate estimate --watch\n```\n\nUseful when you're experimenting with different instance sizes or toggling features like Multi-AZ — you see the cost impact immediately.\n\n## What's Next\n\nNext up: Terraform support (reading `.tfplan` JSON instead of `cdk.out`), a Pulumi adapter, and better variable cost modeling for services like Aurora Serverless v2 where scaling isn't linear.\n\nBeyond that, I'm looking at multicloud support — GCP and Azure pricing APIs — so Slate can estimate costs regardless of which cloud you're deploying to.\n\nIf you want to know what your infrastructure costs before you deploy:\n\n```bash\nnpm install --save-dev slate-cost\nnpx cdk synth\nnpx slate estimate\n```\n\nThree commands, real prices.\n"}}