Last week my AWS bill hit $300. I knew there was waste hiding somewhere. Forgotten EBS volumes, idle Elastic IPs, snapshots from six months ago that nobody remembered creating.
I could open Cost Explorer. Click through dashboards. Manually cross-reference resources.
Or I could let three AI agents do it in 60 seconds.
I built a multi-agent system with CrewAI and Amazon Bedrock that scans everything, identifies waste, and writes a prioritized report with exact dollar savings. It found $125/month I was burning for nothing.
Who This Is For
You run workloads on AWS. Your bill has crept up. You suspect there's waste but don't have time to audit every resource manually. You have 10+ resources running and haven't done a proper audit in 3 months. You want something that scans your account and tells you exactly what to delete, release, or downsize, with dollar amounts attached.
When this won't help: If your account has fewer than 5 resources or you're still in free tier, the overhead of setting this up isn't worth it. Just check Cost Explorer manually.
Table of Contents
- The Architecture
- Why Not Just Use Trusted Advisor?
- Why CrewAI + Bedrock
- The Custom Tool
- Running It
- What It Found
- Gotchas You'll Hit
- Web UI (Bonus)
- Key Lessons
- Cleanup
The Architecture
Three agents, one pipeline:
Scanner → Optimizer → Report Writer
↓ ↓ ↓
AWS APIs Reasoning Executive Report
Each agent has a single job.
Agent 1: Cost Intelligence Analyst scans your account using boto3. EC2 instances, EBS volumes, Elastic IPs, snapshots, S3 buckets, and Cost Explorer data. Raw facts with exact numbers.
Agent 2: Optimization Strategist takes the scan results and identifies savings. Orphaned volumes that can be deleted. Unattached IPs burning $3.60/month each. gp2 volumes that should be gp3. Reserved Instance candidates running 24/7 on On-Demand.
Agent 3: Executive Report Writer produces a markdown report with prioritized actions, dollar amounts, and risk levels. The kind of thing you can hand to a CTO.
The pipeline runs sequentially. Each agent passes context to the next through CrewAI's task handoff.
Why Not Just Use Trusted Advisor?
Fair question. AWS already has cost tools. Here's why they weren't enough for me:
| Tool | Limitation |
|---|---|
| Trusted Advisor (free tier) | Only 7 checks. Misses orphaned volumes, old snapshots, gp2→gp3 opportunities |
| Compute Optimizer | EC2 and Lambda only. No EBS, no EIPs, no S3 lifecycle gaps |
| Cost Explorer | Shows WHAT you spent, not WHAT TO DO about it |
| Infracost | Terraform-only. Useless if you clicked things in the console |
The multi-agent approach covers all of these in one pass AND produces an actionable report with prioritized fixes. You get "delete vol-0abc123 to save $20/month" instead of a dashboard you have to interpret yourself.
Plus it runs on YOUR schedule. Cron it weekly. Get a fresh report every Monday morning.
Why CrewAI + Bedrock
I tried a single-prompt approach first. One giant prompt asking the LLM to scan AND analyze AND write a report. The results were mediocre. The model tried to do everything and did nothing well. It hallucinated resource IDs that didn't exist because it was juggling too many concerns at once.
Multi-agent fixes this. Each agent has a focused role, a specific backstory, and constrained output expectations. The scanner doesn't try to optimize. The optimizer doesn't write pretty reports.
Amazon Bedrock Nova Pro handles the reasoning. On EC2, the IAM role handles auth automatically. No API keys to manage:
from crewai import LLM
llm = LLM(
model="bedrock/amazon.nova-pro-v1:0",
temperature=0.2,
)
Cost per run: about $0.01. The savings it finds will be 100-1000x that.
The Custom Tool: Scanning AWS
CrewAI agents need tools to interact with the world. I built one custom tool that wraps boto3:
from crewai.tools import BaseTool
class AWSCostScannerTool(BaseTool):
name: str = "AWS Cost Scanner"
description: str = (
"Scans your AWS account for running resources and costs."
)
def _run(self, scan_type: str = "all") -> str:
results = {}
results["ec2_instances"] = self._scan_ec2()
results["ebs_volumes"] = self._scan_ebs()
results["elastic_ips"] = self._scan_eips()
results["ebs_snapshots"] = self._scan_snapshots()
results["s3_buckets"] = self._scan_s3()
results["cost_data"] = self._scan_costs()
return json.dumps(results, indent=2, default=str)
Each _scan_* method is a simple boto3 call. For example, _scan_ebs() runs ec2.describe_volumes() and flags any volume where Attachments is empty. That's an orphan. The scanner doesn't decide what to do about it. It just reports: "vol-0abc123, 20GB gp2, unattached, $2.00/month."
The optimizer doesn't need tools. It's pure reasoning. Takes the scan output and applies FinOps logic: "This volume has no attachments, it's orphaned, that's $20/month wasted."
Running It
git clone https://github.com/SimplyNadaf/crewai-aws-cost-optimizer-ai-agent.git
cd crewai-aws-cost-optimizer-ai-agent
pip3.11 install -r requirements.txt
export AWS_DEFAULT_REGION=us-east-1
python3.11 main.py
You'll see each agent working in sequence. The scanner calls AWS APIs, the optimizer reasons about the results, the report writer formats the final output.
Total time: under 60 seconds for a typical account.
What It Found on My Account
Three orphaned EBS volumes: $33/month. Two unattached Elastic IPs: $7.20/month. A running t3.medium that should be reserved: $82/month in potential savings. Two snapshots from January that nobody needed anymore.
Here's a trimmed version of the actual report output:
╭────────────────── 📊 Cost Optimization Report ──────────────╮
│ │
│ Executive Summary │
│ Current spend: $300/mo → Savings: $125/mo (41.7%) │
│ │
│ Top Savings Opportunities │
│ │
│ Priority Resource Action Savings │
│ ───────────────────────────────────────────────────────── │
│ 1 Orphaned EBS (×3) Delete volumes $33.00 │
│ 2 Elastic IPs (×2) Release $7.20 │
│ 3 EC2 i-0f7b... Reserved (1yr) $82.00 │
│ 4 EBS vol-02b... gp2 → gp3 $3.00 │
│ │
│ Quick Wins (zero risk) │
│ • Delete 3 orphaned EBS volumes → save $33/month │
│ • Release 2 unused Elastic IPs → save $7.20/month │
│ │
╰──────────────────────────────────────────────────────────────╯
The quick wins (deleting orphaned volumes, releasing unused IPs) took five minutes to act on. $40/month saved before lunch.
Gotchas You'll Hit
Saved you the debugging time:
Python version matters. CrewAI requires 3.11+. If you're on Amazon Linux 2023, use python3.11 and pip3.11 explicitly. The default python3 is 3.9 and will throw ModuleNotFoundError.
Enable Nova Pro in Bedrock Console first. Go to Bedrock > Model access > Request access for Amazon Nova Pro. Takes 1-2 minutes to approve. Without this you'll get AccessDeniedException: You don't have access to the model.
Cost Explorer needs 24 hours. If you've never used Cost Explorer before, AWS needs ~24h to start collecting data. First run might return empty cost breakdowns. The agents still find orphaned resources, just no historical spend data.
Set the region as an env var, not just config. CrewAI reads AWS_DEFAULT_REGION from the environment, not from ~/.aws/config. Always export it explicitly or the boto3 calls will fail with NoRegionError.
The Web UI (Bonus)
I also built a Streamlit dashboard that wraps the same agents. One-click scan, visual findings, and remediation buttons that delete the orphaned resources for you.
But the CLI version is the core. No web server needed. SSH into any EC2 instance, clone, run, done.
Key Lessons
Separate scanning from reasoning. Agents with tools should gather data. Agents without tools should think. My first version had one agent doing both. It mixed up resource IDs, merged findings from different services, and produced a report with numbers that didn't add up.
Temperature 0.2 for cost analysis. I tried 0.7 first. The optimizer started "suggesting" resources that might exist and estimating savings based on vibes. At 0.2 it sticks to the facts the scanner reported. Nothing invented.
IAM roles over API keys. On EC2, there's zero credential management. The boto3 client picks up the instance role automatically. One less thing to configure, one less secret to leak. I've seen three repos on GitHub with AWS keys in their .env files pushed by accident. Don't be that person.
CrewAI's sequential process fits pipelines. When agents need each other's output, sequential beats hierarchical. Each task's output becomes the next task's context. Parallel would make sense if the agents were independent, but ours depend on each other's findings.
Cleanup
If you created demo resources for testing, remove them:
# Delete orphaned volumes the agents found
aws ec2 delete-volume --volume-id vol-xxx --region us-east-1
# Release unused Elastic IPs
aws ec2 release-address --allocation-id eipalloc-xxx --region us-east-1
# Or use the included cleanup script
bash scripts/cleanup-demo-resources.sh
⚠️ The demo script (
scripts/create-demo-resources.sh) creates ~$40/month in dummy resources for testing. Always run cleanup after.
Try It
simplynadaf
/
crewai-aws-cost-optimizer-ai-agent
3 AI agents analyze your AWS account and find cost savings — powered by CrewAI + Amazon Bedrock
💰 AWS Cost Optimizer Crew
3 AI agents scan your AWS account, find waste, and produce an executive savings report - in under 60 seconds.
⭐ If this helped you, give it a star! It helps others find it.
Video Tutorial • Getting Started • How It Works • Demo • Contributing
🎬 Video Tutorial
Watch the full demo - from zero to finding $125/month in AWS waste:
In the video you'll see:
- Browsing the source code and architecture on GitHub
- Live deployment on an EC2 instance (Amazon Linux 2023)
- All 3 agents working in real-time (Scanner → Optimizer → Report Writer)
- Streamlit web dashboard with one-click remediation
🤔 The Problem
Your AWS bill keeps climbing. Resources get created and forgotten - orphaned EBS volumes, unattached Elastic IPs, old snapshots nobody…
Two minutes to set up. A penny to run. Might save you hundreds.
What's eating YOUR AWS budget? Have you tried multi-agent approaches for infrastructure tasks? Drop your experience below.
Follow me for more on AWS architecture, DevOps, and AI Infrastructure:
Portfolio | LinkedIn | Dev.to | YouTube | Email | AWS Builder Center | X
Top comments (1)
🎥 I also recorded a full demo showing the architecture, deployment, and the AI agents finding the hidden AWS costs:
👉 youtu.be/BDJytOAjtlo
Would you trust an AI agent to analyze your AWS infrastructure? 🤔