Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .claude-plugin/marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@
"source": "./plugins/aws-amplify",
"tags": ["aws", "amplify", "fullstack"],
"version": "1.0.0"
},
{
"category": "cost-optimization",
"description": "Analyze DynamoDB tables for cost optimization: capacity mode, table class, utilization, and unused GSI detection.",
"keywords": [
"aws",
"aws agent skills",
"amazon",
"dynamodb",
"cost-optimization",
"capacity",
"on-demand",
"provisioned",
"table-class",
"gsi"
],
"name": "dynamodb-cost-optimizer",
"source": "./plugins/dynamodb-cost-optimizer",
"tags": [
"aws",
"dynamodb",
"cost-optimization"
],
"version": "1.0.0"
}
]
}
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ plugins/amazon-location-service @awslabs/agent-plugins-admins @awslabs/agent
plugins/aws-amplify @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-amplify
plugins/aws-serverless @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-aws-serverless
plugins/deploy-on-aws @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-deploy-on-aws
plugins/dynamodb-cost-optimizer @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @LeeroyHannigan
plugins/migration-to-aws @awslabs/agent-plugins-admins @awslabs/agent-plugins-maintainers @awslabs/agent-plugins-migrate-to-aws

## File must end with CODEOWNERS file
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ build/
.DS_Store
Thumbs.db

# Python
__pycache__/
*.pyc

# IDE
.idea/
.vscode/
Expand Down
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ To maximize the benefits of plugin-assisted development while maintaining securi
| **migration-to-aws** | Migrate GCP infrastructure to AWS with resource discovery, architecture mapping, cost analysis, and execution planning | Available |
| **aws-amplify** | Build full-stack apps with AWS Amplify Gen 2 using guided workflows for auth, data, storage, and functions | Available |
| **aws-serverless** | Build serverless applications with Lambda, API Gateway, EventBridge, Step Functions, and durable functions | Available |
| **dynamodb-cost-optimizer** | Analyze DynamoDB tables for cost optimization: capacity mode, table class, utilization, and unused GSI detection | Available |

## Installation

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

```bash
/plugin install deploy-on-aws@agent-plugins-for-aws
/plugin install dynamodb-cost-optimizer@agent-plugins-for-aws
```

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

## dynamodb-cost-optimizer

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.

### Workflow

1. **Discover** - List and describe DynamoDB tables in target region(s)
2. **Analyze** - Run all four analyzers in parallel with automatic pricing lookup
3. **Report** - Present savings recommendations in a formatted table

### Agent Skill Triggers

| Agent Skill | Triggers |
| --------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| **optimize-dynamodb** | "optimize DynamoDB", "DynamoDB cost analysis", "reduce DynamoDB costs", "on-demand vs provisioned", "table class analysis", "find unused GSIs" |

### Prerequisites

- Python 3.9+ with boto3
- AWS credentials with: `dynamodb:DescribeTable`, `dynamodb:ListTables`, `dynamodb:DescribeContinuousBackups`, `cloudwatch:GetMetricData`, `pricing:GetProducts`, `ce:GetCostAndUsage`

## Requirements

- Claude Code >=2.1.29 or [Cursor >= 2.5](https://cursor.com/changelog/2-5)
Expand Down
22 changes: 22 additions & 0 deletions plugins/dynamodb-cost-optimizer/.claude-plugin/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"author": {
"name": "Amazon Web Services"
},
"description": "Analyze DynamoDB tables for cost optimization: capacity mode, table class, utilization, and unused GSI detection.",
"homepage": "https://github.com/awslabs/agent-plugins",
"keywords": [
"aws",
"dynamodb",
"cost-optimization",
"capacity",
"provisioned",
"on-demand",
"table-class",
"utilization",
"gsi"
],
"license": "Apache-2.0",
"name": "dynamodb-cost-optimizer",
"repository": "https://github.com/awslabs/agent-plugins",
"version": "1.0.0"
}
105 changes: 105 additions & 0 deletions plugins/dynamodb-cost-optimizer/skills/optimize-dynamodb/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
name: optimize-dynamodb
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."
license: Apache-2.0
metadata:
tags: aws, dynamodb, cost-optimization, capacity, provisioned, on-demand, table-class, utilization, gsi
dependencies: python>=3.9, boto3
---

# DynamoDB Cost Optimizer

Scripts are fully self-contained — they fetch pricing, metrics, and costs from AWS
via boto3 and return only a small summary. Execute them, do NOT reimplement the logic.

## Prerequisites

Before running any scripts, detect the Python command:

1. Run `python --version`. If it returns Python 3.9+, use `python` for all scripts.
2. If not, try `python3 --version`. If 3.9+, use `python3` for all scripts.
3. If neither works, tell the user to install Python 3.
4. Run `<python> -c "import boto3"`. If it fails, tell the user: `pip install boto3`.
5. AWS credentials configured with: `dynamodb:DescribeTable`, `dynamodb:ListTables`,
`dynamodb:DescribeContinuousBackups`, `cloudwatch:GetMetricData`, `pricing:GetProducts`,
`ce:GetCostAndUsage`

## Workflow

### Step 1: Region

Ask user for AWS region(s). Default: `us-east-1`. Supports multiple regions.

### Step 2: Run Analysis

Use the batch script to analyze tables. It auto-discovers all tables when `tables` is omitted.
Pricing is fetched automatically per region — no need to pass it.

Script: `scripts/analyze_all.py`

IMPORTANT: Run the script from the user's current working directory using the absolute path
to the script. This ensures the report is saved locally.

Example:
`python3 /path/to/skill/scripts/analyze_all.py '{"region":"REGION","days":14}'`

All tables in a region:
`{"region":"REGION","days":14}`

Specific tables:
`{"region":"REGION","tables":["table1","table2"],"days":14}`

Multi-region:
`{"regions":{"us-east-1":["t1","t2"],"eu-west-1":["t3"]},"days":14}`

This runs all four analyzers (capacity mode, table class, utilization, unused GSIs)
with parallel execution (10 concurrent by default). One command, one approval.

Individual scripts are also available if the user only wants one type of analysis.
These require a `prices` object — use `scripts/get_pricing.py REGION` to fetch it first:

- `scripts/capacity_mode.py` — Input: `{"region":"REGION","tableName":"TABLE","days":14,"prices":PRICING}`
- `scripts/table_class.py` — Input: `{"region":"REGION","tableName":"TABLE","days":14,"prices":PRICING}`
- `scripts/utilization.py` — Input: `{"region":"REGION","tableName":"TABLE","days":14,"prices":PRICING}`
- `scripts/unused_gsi.py` — Input: `{"region":"REGION","tableName":"TABLE","days":14}`

### Step 3: Present Results

The script outputs a summary line and saves the full report to `dynamodb-cost-report.md`
in the user's current working directory.

DO NOT read or summarize the report file. Simply display the script's output, which
includes the summary and file path. The user can open the file themselves if needed.

After displaying the output, ask if the user wants CLI commands for any recommendations.

### Step 4: Generate Actions

For accepted recommendations:

```bash
# Switch to on-demand
aws dynamodb update-table --table-name TABLE --billing-mode PAY_PER_REQUEST

# Switch to provisioned
aws dynamodb update-table --table-name TABLE --billing-mode PROVISIONED \
--provisioned-throughput ReadCapacityUnits=RCU,WriteCapacityUnits=WCU

# Change table class
aws dynamodb update-table --table-name TABLE --table-class STANDARD_INFREQUENT_ACCESS

# Delete unused GSI
aws dynamodb update-table --table-name TABLE \
--global-secondary-index-updates '[{"Delete":{"IndexName":"GSI_NAME"}}]'
```

DO NOT execute update commands without explicit user confirmation.

## Error Handling

- Script fails → show error output, DO NOT reimplement logic.
- Reserved capacity detected → table class script handles this, reports it.
- ON_DEMAND table → utilization script handles this, reports it.
- CloudWatch throttling → scripts retry with exponential backoff (up to 5 retries).
- Per-table errors → reported in the output, other tables still analyzed.
- AWS credentials missing → scripts exit with clear error message.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
boto3
Loading
Loading