Skip to content

Commit aecab44

Browse files
author
Lee Hannigan
committed
feat: add dynamodb-cost-optimizer plugin
Adds a new plugin that analyzes DynamoDB tables for cost optimization across four dimensions: capacity mode, table class, utilization right-sizing, and unused GSI detection. Closes #51
1 parent 0555646 commit aecab44

File tree

20 files changed

+2071
-0
lines changed

20 files changed

+2071
-0
lines changed

.claude-plugin/marketplace.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,30 @@
115115
"source": "./plugins/aws-amplify",
116116
"tags": ["aws", "amplify", "fullstack"],
117117
"version": "1.0.0"
118+
},
119+
{
120+
"category": "cost-optimization",
121+
"description": "Analyze DynamoDB tables for cost optimization: capacity mode, table class, utilization, and unused GSI detection.",
122+
"keywords": [
123+
"aws",
124+
"aws agent skills",
125+
"amazon",
126+
"dynamodb",
127+
"cost-optimization",
128+
"capacity",
129+
"on-demand",
130+
"provisioned",
131+
"table-class",
132+
"gsi"
133+
],
134+
"name": "dynamodb-cost-optimizer",
135+
"source": "./plugins/dynamodb-cost-optimizer",
136+
"tags": [
137+
"aws",
138+
"dynamodb",
139+
"cost-optimization"
140+
],
141+
"version": "1.0.0"
118142
}
119143
]
120144
}

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ plugins/amazon-location-service @awslabs/agent-plugins-admins @awslabs/agent
3434
plugins/aws-amplify @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-amplify
3535
plugins/aws-serverless @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-aws-serverless
3636
plugins/deploy-on-aws @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-deploy-on-aws
37+
plugins/dynamodb-cost-optimizer @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @LeeroyHannigan
3738
plugins/migration-to-aws @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-migrate-to-aws
3839

3940
## File must end with CODEOWNERS file

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ build/
1818
.DS_Store
1919
Thumbs.db
2020

21+
# Python
22+
__pycache__/
23+
*.pyc
24+
2125
# IDE
2226
.idea/
2327
.vscode/

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ To maximize the benefits of plugin-assisted development while maintaining securi
3333
| **migration-to-aws** | Migrate GCP infrastructure to AWS with resource discovery, architecture mapping, cost analysis, and execution planning | Available |
3434
| **aws-amplify** | Build full-stack apps with AWS Amplify Gen 2 using guided workflows for auth, data, storage, and functions | Available |
3535
| **aws-serverless** | Build serverless applications with Lambda, API Gateway, EventBridge, Step Functions, and durable functions | Available |
36+
| **dynamodb-cost-optimizer** | Analyze DynamoDB tables for cost optimization: capacity mode, table class, utilization, and unused GSI detection | Available |
3637

3738
## Installation
3839

@@ -48,6 +49,7 @@ To maximize the benefits of plugin-assisted development while maintaining securi
4849

4950
```bash
5051
/plugin install deploy-on-aws@agent-plugins-for-aws
52+
/plugin install dynamodb-cost-optimizer@agent-plugins-for-aws
5153
```
5254

5355
or
@@ -199,6 +201,27 @@ Design, build, deploy, test, and debug serverless applications with AWS Lambda,
199201
| --------------------------- | --------------------------------------------- | --------------------------------------------- |
200202
| **SAM template validation** | After edits to `template.yaml`/`template.yml` | Runs `sam validate` and reports errors inline |
201203

204+
## dynamodb-cost-optimizer
205+
206+
Analyzes DynamoDB tables for cost optimization opportunities across four dimensions: capacity mode (on-demand vs provisioned), table class (Standard vs Standard-IA), utilization right-sizing, and unused GSI detection.
207+
208+
### Workflow
209+
210+
1. **Discover** - List and describe DynamoDB tables in target region(s)
211+
2. **Analyze** - Run all four analyzers in parallel with automatic pricing lookup
212+
3. **Report** - Present savings recommendations in a formatted table
213+
214+
### Agent Skill Triggers
215+
216+
| Agent Skill | Triggers |
217+
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
218+
| **optimize-dynamodb** | "optimize DynamoDB", "DynamoDB cost analysis", "reduce DynamoDB costs", "on-demand vs provisioned", "table class analysis", "find unused GSIs" |
219+
220+
### Prerequisites
221+
222+
- Python 3.9+ with boto3
223+
- AWS credentials with: `dynamodb:DescribeTable`, `dynamodb:ListTables`, `dynamodb:DescribeContinuousBackups`, `cloudwatch:GetMetricData`, `pricing:GetProducts`, `ce:GetCostAndUsage`
224+
202225
## Requirements
203226

204227
- Claude Code >=2.1.29 or [Cursor >= 2.5](https://cursor.com/changelog/2-5)
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"author": {
3+
"name": "Amazon Web Services"
4+
},
5+
"description": "Analyze DynamoDB tables for cost optimization: capacity mode, table class, utilization, and unused GSI detection.",
6+
"homepage": "https://github.com/awslabs/agent-plugins",
7+
"keywords": [
8+
"aws",
9+
"dynamodb",
10+
"cost-optimization",
11+
"capacity",
12+
"provisioned",
13+
"on-demand",
14+
"table-class",
15+
"utilization",
16+
"gsi"
17+
],
18+
"license": "Apache-2.0",
19+
"name": "dynamodb-cost-optimizer",
20+
"repository": "https://github.com/awslabs/agent-plugins",
21+
"version": "1.0.0"
22+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
name: optimize-dynamodb
3+
description: "Analyze DynamoDB tables for cost optimization opportunities. Triggers on: optimize DynamoDB, DynamoDB cost analysis, reduce DynamoDB costs, DynamoDB capacity mode, on-demand vs provisioned, table class analysis, unused GSI, DynamoDB utilization, right-size DynamoDB."
4+
license: Apache-2.0
5+
metadata:
6+
tags: aws, dynamodb, cost-optimization, capacity, provisioned, on-demand, table-class, utilization, gsi
7+
dependencies: python>=3.9, boto3
8+
---
9+
10+
# DynamoDB Cost Optimizer
11+
12+
Scripts are fully self-contained — they fetch pricing, metrics, and costs from AWS
13+
via boto3 and return only a small summary. Execute them, do NOT reimplement the logic.
14+
15+
## Prerequisites
16+
17+
Before running any scripts, detect the Python command:
18+
19+
1. Run `python --version`. If it returns Python 3.9+, use `python` for all scripts.
20+
2. If not, try `python3 --version`. If 3.9+, use `python3` for all scripts.
21+
3. If neither works, tell the user to install Python 3.
22+
4. Run `<python> -c "import boto3"`. If it fails, tell the user: `pip install boto3`.
23+
5. AWS credentials configured with: `dynamodb:DescribeTable`, `dynamodb:ListTables`,
24+
`dynamodb:DescribeContinuousBackups`, `cloudwatch:GetMetricData`, `pricing:GetProducts`,
25+
`ce:GetCostAndUsage`
26+
27+
## Workflow
28+
29+
### Step 1: Region
30+
31+
Ask user for AWS region(s). Default: `us-east-1`. Supports multiple regions.
32+
33+
### Step 2: Run Analysis
34+
35+
Use the batch script to analyze tables. It auto-discovers all tables when `tables` is omitted.
36+
Pricing is fetched automatically per region — no need to pass it.
37+
38+
Script: `scripts/analyze_all.py`
39+
40+
IMPORTANT: Run the script from the user's current working directory using the absolute path
41+
to the script. This ensures the report is saved locally.
42+
43+
Example:
44+
`python3 /path/to/skill/scripts/analyze_all.py '{"region":"REGION","days":14}'`
45+
46+
All tables in a region:
47+
`{"region":"REGION","days":14}`
48+
49+
Specific tables:
50+
`{"region":"REGION","tables":["table1","table2"],"days":14}`
51+
52+
Multi-region:
53+
`{"regions":{"us-east-1":["t1","t2"],"eu-west-1":["t3"]},"days":14}`
54+
55+
This runs all four analyzers (capacity mode, table class, utilization, unused GSIs)
56+
with parallel execution (10 concurrent by default). One command, one approval.
57+
58+
Individual scripts are also available if the user only wants one type of analysis.
59+
These require a `prices` object — use `scripts/get_pricing.py REGION` to fetch it first:
60+
61+
- `scripts/capacity_mode.py` — Input: `{"region":"REGION","tableName":"TABLE","days":14,"prices":PRICING}`
62+
- `scripts/table_class.py` — Input: `{"region":"REGION","tableName":"TABLE","days":14,"prices":PRICING}`
63+
- `scripts/utilization.py` — Input: `{"region":"REGION","tableName":"TABLE","days":14,"prices":PRICING}`
64+
- `scripts/unused_gsi.py` — Input: `{"region":"REGION","tableName":"TABLE","days":14}`
65+
66+
### Step 3: Present Results
67+
68+
The script outputs a summary line and saves the full report to `dynamodb-cost-report.md`
69+
in the user's current working directory.
70+
71+
DO NOT read or summarize the report file. Simply display the script's output, which
72+
includes the summary and file path. The user can open the file themselves if needed.
73+
74+
After displaying the output, ask if the user wants CLI commands for any recommendations.
75+
76+
### Step 4: Generate Actions
77+
78+
For accepted recommendations:
79+
80+
```bash
81+
# Switch to on-demand
82+
aws dynamodb update-table --table-name TABLE --billing-mode PAY_PER_REQUEST
83+
84+
# Switch to provisioned
85+
aws dynamodb update-table --table-name TABLE --billing-mode PROVISIONED \
86+
--provisioned-throughput ReadCapacityUnits=RCU,WriteCapacityUnits=WCU
87+
88+
# Change table class
89+
aws dynamodb update-table --table-name TABLE --table-class STANDARD_INFREQUENT_ACCESS
90+
91+
# Delete unused GSI
92+
aws dynamodb update-table --table-name TABLE \
93+
--global-secondary-index-updates '[{"Delete":{"IndexName":"GSI_NAME"}}]'
94+
```
95+
96+
DO NOT execute update commands without explicit user confirmation.
97+
98+
## Error Handling
99+
100+
- Script fails → show error output, DO NOT reimplement logic.
101+
- Reserved capacity detected → table class script handles this, reports it.
102+
- ON_DEMAND table → utilization script handles this, reports it.
103+
- CloudWatch throttling → scripts retry with exponential backoff (up to 5 retries).
104+
- Per-table errors → reported in the output, other tables still analyzed.
105+
- AWS credentials missing → scripts exit with clear error message.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
boto3

0 commit comments

Comments
 (0)