-
Notifications
You must be signed in to change notification settings - Fork 31
Description
Is this related to an existing feature request or issue?
No
Summary
A new plugin dynamodb-cost-optimizer that analyzes existing DynamoDB tables and identifies cost optimization opportunities. The plugin includes a single skill (optimize-dynamodb) that runs four analyzers: capacity mode (on-demand vs provisioned), table class (Standard vs Standard-IA), utilization right-sizing, and unused GSI detection. It fetches live metrics from CloudWatch, pricing from the AWS Pricing API, and cost data from Cost Explorer to produce actionable savings recommendations.
Use case
DynamoDB cost optimization requires analyzing multiple data sources (CloudWatch metrics, pricing APIs, Cost Explorer) and applying domain-specific logic (autoscaling simulation, storage-to-throughput ratio analysis, utilization thresholds). This is tedious to do manually, especially across many tables or regions.
With this plugin, a developer can say "optimize my DynamoDB tables" or "analyze DynamoDB costs in us-east-1" and get a formatted report showing exactly where money is being wasted and what to change — without needing deep DynamoDB pricing expertise.
Example output:
Region: us-east-1 | Analysis: 14 days | Tables: 3 | Savings: $142.50/month ($1,710.00/year)
┌───────────┬──────────────────────────────────────────────┬──────────────┐
│ Table │ Recommendation │ Savings │
├───────────┼──────────────────────────────────────────────┼──────────────┤
│ orders │ Billing Mode: Provisioned → On-Demand │ $85.00/mo │
├───────────┼──────────────────────────────────────────────┼──────────────┤
│ sessions │ Table Class: Standard → Standard-IA │ $45.00/mo │
├───────────┼──────────────────────────────────────────────┼──────────────┤
│ users │ Unused GSI: Review idx-email (zero reads) │ $12.50/mo │
├───────────┼──────────────────────────────────────────────┼──────────────┤
│ TOTAL │ │ $142.50/mo │
└───────────┴──────────────────────────────────────────────┴──────────────┘
Already optimized (1): audit-logs
Proposal
Plugin structure
plugins/dynamodb-cost-optimizer/
├── .claude-plugin/
│ └── plugin.json
└── skills/
└── optimize-dynamodb/
├── SKILL.md
├── requirements.txt # boto3
├── scripts/
│ ├── config.py # Shared constants and utilities
│ ├── discover.py # Table discovery via DynamoDB API
│ ├── get_pricing.py # Pricing via AWS Pricing API
│ ├── cw_batch.py # CloudWatch batch metric fetching with retry
│ ├── autoscaling_sim.py # Autoscaling simulation for capacity mode analysis
│ ├── capacity_mode.py # On-demand vs provisioned analysis
│ ├── table_class.py # Standard vs Standard-IA analysis
│ ├── utilization.py # Right-sizing analysis for provisioned tables + GSIs
│ ├── unused_gsi.py # Unused GSI detection with savings estimation
│ └── analyze_all.py # Batch orchestrator with formatted output
└── tests/
├── test_config.py
├── test_analyzers.py
└── test_infrastructure.py
How it works
- Agent asks user for region(s) and optionally specific table names
discover.pylists/describes tables via DynamoDB APIanalyze_all.pyruns all four analyzers in parallel (10 concurrent workers), auto-fetching pricing per region- Script outputs a pre-formatted text report that the agent displays directly
- Agent can generate AWS CLI commands for any accepted recommendations
Design decisions
- Scripts are self-contained — Each script fetches its own data from AWS. The agent just pipes JSON in and displays the output. No MCP servers required.
- No MCP dependency — Uses
allowed-tools: Bash(python3 scripts/*)instead of MCP servers, keeping the plugin simple and portable. - Parallel execution — All four analyzers run per table in a single
analyze_all.pyinvocation, minimizing agent tool calls and user approvals. - Autoscaling simulation — Capacity mode analysis simulates optimal autoscaling behavior (scale-out/scale-in rules per AWS documentation) rather than using simple averages, producing more accurate provisioned cost estimates.
Prerequisites
- Python 3.9+ with boto3
- AWS credentials with:
dynamodb:DescribeTable,dynamodb:ListTables,cloudwatch:GetMetricData,pricing:GetProducts,ce:GetCostAndUsage
Test coverage
53 unit tests covering all analyzers, config utilities, CloudWatch batching/retry, pricing parsing/pagination, table discovery, and batch orchestration.
Out of scope
- Auto-applying changes — The plugin reports recommendations but does not execute them. The agent can generate CLI commands, but only with explicit user confirmation.
- Reserved capacity recommendations — The plugin detects reserved capacity and notes it may affect estimates, but does not recommend purchasing or modifying reservations.
- DynamoDB Streams / DAX / backup costs — Only covers table, GSI, and throughput costs.
- Cross-account analysis — Analyzes tables accessible with the configured credentials only.
Potential challenges
- Python dependency — Requires Python 3.9+ and boto3 installed. The SKILL.md includes prerequisite detection steps, but users without Python will need to install it.
- CloudWatch data retention — Analysis window is capped at 90 days. Tables created recently may not have enough metric history for accurate recommendations.
- Pricing API availability — The AWS Pricing API is only available in us-east-1 and ap-south-1. The plugin hardcodes us-east-1 for pricing calls and filters by the target region.
- Cost Explorer permissions — The table class analyzer uses Cost Explorer to detect reserved capacity. If the user's credentials lack
ce:GetCostAndUsage, the check fails gracefully with a warning note rather than blocking the analysis. - Large accounts — Accounts with hundreds of tables will work (parallel execution with 10 workers, CloudWatch retry with backoff) but may take several minutes.
Dependencies and Integrations
- Runtime: Python 3.9+, boto3 (standard AWS SDK)
- AWS APIs: DynamoDB, CloudWatch, Pricing, Cost Explorer
- No MCP servers required
- No external dependencies beyond boto3
## Alternative solutions
- **AWS Cost Explorer console** — Shows DynamoDB costs but doesn't provide specific optimization recommendations (capacity mode, table class, right-sizing).
- **AWS Trusted Advisor** — Covers some DynamoDB checks but requires Business/Enterprise support plans and doesn't do autoscaling simulation or table class analysis.
- **Manual CloudWatch analysis** — Possible but time-consuming, especially across many tables and regions.