Analyzes and reduces cloud and infrastructure costs: cost explorer queries, idle resource detection, and rightsizing.
Agentic Workflow: Read -> Reason -> Act (cost-optimization)
You are cost-optimization (finops) — a sub-agent that Reads, Reasons, and Acts via allowed-tools.
1. Read — finops context for cost-optimization
- Domain: Analyzes and reduces cloud and infrastructure costs: cost explorer queries, idle resource detection, and rightsizing.
- cloud-cost-analysis: Query AWS cost data and find waste —
aws ce get-cost-and-usage --time-period Start=$(date +%Y-%m-01) --granularity MO
- Check
knowledge and prerequisites: aws, terraform, kubernetes, cloud-cpu
2. Reason — think for cost-optimization
- For
cloud-cost-analysis: Query AWS cost data and find waste — decide which checks to run
- Evaluate trust/policy:
kdesk trust + kdesk doctor patterns for your inputs
3. Act — execute with cost-optimization tools
- Tools:
Glob, Grep, Read, Aws (see frontmatter tools/allowed-tools)
- Use
safe_path for any write; record evidence (paths, checksums)
- Fingerprint:
cost-optimization:d7052638
Cost Optimization
Finds and eliminates cloud waste: underused compute, oversized storage, and
services running with no traffic.
When to Use
- Monthly spend review
- Before renegotiating commitments or Reserved Instances
- Identifying orphaned resources after decommissions
Real Commands
# Spend by service this month
aws ce get-cost-and-usage --time-period Start=$(date +%Y-%m-01) --granularity MONTHLY --metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICE
# 6-month trend
aws ce get-cost-and-usage --time-period Start=$(date -d '-6 months' +%Y-%m-01) --granularity MONTHLY --metrics UnblendedCost
# Idle instances (low CPU over 7 days)
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-xxxx --start-time $(date -d '-7 days' -u +%FT%TZ) --end-time $(date -u +%FT%TZ) --period 3600 --statistics Average
# Unattached elastic IPs
aws ec2 describe-addresses --query 'Addresses[?AssociationId==null].PublicIp'
# Storage inventory
aws s3 ls --summarize --human-readable s3://bucket
Container/VM waste checks
kubectl top nodes
kubectl get pods -A --field-selector=status.phase=Running | wc -l
Best Practices
- Tag resources (env/cost-center) and group cost queries by tags
- Right-size instances that run < 10% CPU for weeks
- Schedule dev/staging to stop outside business hours
- Delete unattached EIPs, unused EBS snapshots, and old ECR images
- Re-evaluate RIs/SPs quarterly against actual utilization
Example Response
Produces a spend breakdown by service, a waste list with per-item monthly cost,
and prioritized recommendations with expected savings.
Capabilities
cloud-cost-analysis
Query AWS cost data and find waste
Parameters:
time-period (string): Start and End dates for the cost query
granularity (string): DAILY, MONTHLY, or HOURLY cost aggregation
group-by (string): Group costs by SERVICE, USAGE_TYPE, or AZ
Commands:
aws ce get-cost-and-usage --time-period Start=$(date +%Y-%m-01) --granularity MONTHLY --metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICE
aws ce get-cost-and-usage --time-period Start=$(date -d '-6 months' +%Y-%m-01) --granularity MONTHLY --metrics UnblendedCost
aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' --query 'Reservations[].Instances[].{id:InstanceId,type:InstanceType}'
aws s3 ls --summarize s3://bucket --human-readable
aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-xxxx --start-time $(date -d '-7 days' -u +%FT%TZ) --end-time $(date -u +%FT%TZ) --period 3600 --statistics Average
Examples:
- aws ce get-cost-and-usage --time-period Start=2024-01-01 --granularity DAILY --metrics UnblendedCost | jq '.ResultsByTime[].Total.UnblendedCost.Amount'
- aws ec2 describe-addresses --query 'Addresses[?AssociationId==null].PublicIp'
- aws cloudwatch get-metric-statistics --namespace AWS/S3 --metric-name BucketSizeBytes --dimensions Name=BucketName,Value=logs
References
1---2name: "cost-optimization"3description: "Analyzes and reduces cloud and infrastructure costs: cost explorer queries, idle resource detection, and rightsizing. Use when working with cloud cost analysis or when the user mentions cloud cost analysis."4license: "MIT"5compatibility: "Requires aws, terraform, kubernetes, cloud-cpu, infracost."6metadata:7 source: https://skillmd.com/skills/opknock/cost-optimization8 author: Kdesk9 version: 2.0.010 category: finops11allowed-tools: "Glob Grep Read Bash(aws:*)"12---1314Analyzes and reduces cloud and infrastructure costs: cost explorer queries, idle resource detection, and rightsizing.1516## Agentic Workflow: Read -> Reason -> Act (cost-optimization)1718You are **cost-optimization** (finops) — a sub-agent that **Reads, Reasons, and Acts** via `allowed-tools`.1920### 1. Read — finops context for `cost-optimization`21- Domain: Analyzes and reduces cloud and infrastructure costs: cost explorer queries, idle resource detection, and rightsizing.22- **cloud-cost-analysis**: Query AWS cost data and find waste — `aws ce get-cost-and-usage --time-period Start=$(date +%Y-%m-01) --granularity MO`23- Check `knowledge` and `prerequisites: aws, terraform, kubernetes, cloud-cpu`2425### 2. Reason — think for `cost-optimization`26- For `cloud-cost-analysis`: Query AWS cost data and find waste — decide which checks to run27- Evaluate trust/policy: `kdesk trust` + `kdesk doctor` patterns for your inputs2829### 3. Act — execute with `cost-optimization` tools30- Tools: `Glob`, `Grep`, `Read`, `Aws` (see frontmatter `tools`/`allowed-tools`)31- Use `safe_path` for any write; record evidence (paths, checksums)32- Fingerprint: `cost-optimization:d7052638`3334# Cost Optimization3536Finds and eliminates cloud waste: underused compute, oversized storage, and37services running with no traffic.3839## When to Use4041- Monthly spend review42- Before renegotiating commitments or Reserved Instances43- Identifying orphaned resources after decommissions4445## Real Commands4647```bash48# Spend by service this month49aws ce get-cost-and-usage --time-period Start=$(date +%Y-%m-01) --granularity MONTHLY --metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICE5051# 6-month trend52aws ce get-cost-and-usage --time-period Start=$(date -d '-6 months' +%Y-%m-01) --granularity MONTHLY --metrics UnblendedCost5354# Idle instances (low CPU over 7 days)55aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-xxxx --start-time $(date -d '-7 days' -u +%FT%TZ) --end-time $(date -u +%FT%TZ) --period 3600 --statistics Average5657# Unattached elastic IPs58aws ec2 describe-addresses --query 'Addresses[?AssociationId==null].PublicIp'5960# Storage inventory61aws s3 ls --summarize --human-readable s3://bucket62```6364## Container/VM waste checks6566```bash67kubectl top nodes68kubectl get pods -A --field-selector=status.phase=Running | wc -l69```7071## Best Practices7273- Tag resources (env/cost-center) and group cost queries by tags74- Right-size instances that run < 10% CPU for weeks75- Schedule dev/staging to stop outside business hours76- Delete unattached EIPs, unused EBS snapshots, and old ECR images77- Re-evaluate RIs/SPs quarterly against actual utilization7879## Example Response8081Produces a spend breakdown by service, a waste list with per-item monthly cost,82and prioritized recommendations with expected savings.8384## Capabilities8586### cloud-cost-analysis87Query AWS cost data and find waste8889**Parameters:**90- `time-period` (string): Start and End dates for the cost query91- `granularity` (string): DAILY, MONTHLY, or HOURLY cost aggregation92- `group-by` (string): Group costs by SERVICE, USAGE_TYPE, or AZ9394**Commands:**95- `aws ce get-cost-and-usage --time-period Start=$(date +%Y-%m-01) --granularity MONTHLY --metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICE`96- `aws ce get-cost-and-usage --time-period Start=$(date -d '-6 months' +%Y-%m-01) --granularity MONTHLY --metrics UnblendedCost`97- `aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' --query 'Reservations[].Instances[].{id:InstanceId,type:InstanceType}'`98- `aws s3 ls --summarize s3://bucket --human-readable`99- `aws cloudwatch get-metric-statistics --namespace AWS/EC2 --metric-name CPUUtilization --dimensions Name=InstanceId,Value=i-xxxx --start-time $(date -d '-7 days' -u +%FT%TZ) --end-time $(date -u +%FT%TZ) --period 3600 --statistics Average`100101**Examples:**102- aws ce get-cost-and-usage --time-period Start=2024-01-01 --granularity DAILY --metrics UnblendedCost | jq '.ResultsByTime[].Total.UnblendedCost.Amount'103- aws ec2 describe-addresses --query 'Addresses[?AssociationId==null].PublicIp'104- aws cloudwatch get-metric-statistics --namespace AWS/S3 --metric-name BucketSizeBytes --dimensions Name=BucketName,Value=logs105106## References107- [AWS Cost Explorer docs](https://docs.aws.amazon.com/cost-management/latest/userguide/ce-what-is.html)108- [AWS Well-Architected cost pillar](https://docs.aws.amazon.com/wellarchitected/latest/cost-optimization-pillar/welcome.html)