engineering

I Built a CLI to Show Me What My AI-Generated Infrastructure Actually Costs

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.

Paul KinyattiPaul Kinyatti··4 min read
Dashboard showing cloud infrastructure cost metrics

Last 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.

That moment — staring at a line item I never consciously chose — is what led me to build Slate.

The Problem

AI 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.

The 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:

  • A NAT Gateway for private subnet internet access: $32.85/month. Fixed cost — same whether you have zero users or ten thousand.
  • 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.
  • DynamoDB provisioned mode instead of on-demand for a table handling 50 requests/day: you're paying for unused capacity.

None of these are wrong in the right context. But they should be conscious choices, not surprises.

What Slate Does

Slate 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.

npx cdk synth
npx slate estimate

Output:

╔══════════════════════════════════════════════╗
║  Slate  │  Region: us-east-1  │  CDK         ║
╠══════════════════════════════════════════════╣
║  FIXED COSTS                                 ║
║  RDS db.t3.micro             $15.33/mo       ║
║  NAT Gateway (1)             $32.85/mo       ║
╠══════════════════════════════════════════════╣
║  Users        Variable    Total              ║
║  0 – 100      $0 ✦        $48 /mo            ║
║  100 – 1k     $2 – $18    $50 – $66 /mo      ║
║  1k – 10k     $18 – $155  $66 – $203 /mo     ║
║  10k – 100k   $155 – $1.4k $203 – $1.4k /mo  ║
║  100k – 1M    $1.4k – $12k $1.4k – $12k /mo  ║
╚══════════════════════════════════════════════╝

The ✦ 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.

Fixed vs Variable

Every 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.

Fixed 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.

This lets you answer: "What does this cost with no users? What about at 10k? Where does cost start climbing?"

Narrowing the Estimate

Slate 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.

traffic_profile:
  lambda:
    invocations_per_user_per_month: 120
    avg_duration_ms: 250
  api_gateway:
    calls_per_user_per_month: 200
  dynamodb:
    reads_per_user_per_month: 500
    writes_per_user_per_month: 80

More 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.

Cost Drift Detection

Slate saves a report after each run. On the next run, it diffs against the previous report and shows what changed:

COST DRIFT:
+ NAT Gateway +$32.85/mo (fixed)
1k–10k: $171/mo → $203/mo (+$32/mo)

In 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.

Cost becomes visible on every PR that touches infrastructure — not a surprise on next month's bill.

Watch Mode

Slate 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.

npx slate estimate --watch

Useful when you're experimenting with different instance sizes or toggling features like Multi-AZ — you see the cost impact immediately.

What's Next

Next 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.

Beyond 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.

If you want to know what your infrastructure costs before you deploy:

npm install --save-dev slate-cost
npx cdk synth
npx slate estimate

Three commands, real prices.

Share:

About the author

Paul Kinyatti

Paul Kinyatti

Building things, writing about them.