Cost Optimization Commands¶
Find money to stop spending. Four of these commands read from Cost Explorer and the Pricing API; the other two build and query a local spot-pricing dataset.
ebs-optimization is usually the highest-yield place to start - unattached volumes and gp2 volumes that should be gp3 are the two most common sources of silent waste.
Commands¶
costops cost-analysis¶
Analyze AWS costs using Cost Explorer.
| Option | Value | Description |
|---|---|---|
--months |
INTEGER |
Number of months to analyze (default: 3) |
--service |
TEXT |
Specific AWS service to analyze (e.g., Amazon Elastic Compute Cloud - Compute) |
--group-by |
service | usage_type | region | account |
Group costs by dimension (default: service) |
--output-file |
TEXT |
Output file for cost analysis (supports .json, .yaml, .csv) |
costops ebs-optimization¶
Analyze EBS volumes for cost optimization opportunities.
| Option | Value | Description |
|---|---|---|
--region |
TEXT |
AWS region to analyze (default: current region) |
--all-regions |
flag | Analyze EBS volumes across all regions |
--volume-type |
gp2 | gp3 | io1 | io2 | st1 | sc1 | standard |
Filter by specific volume type (default: analyze all types) |
--show-recommendations |
flag | Show optimization recommendations (default: enabled) |
--include-cost-estimates |
flag | Include cost savings estimates (requires pricing data) |
--output-file |
TEXT |
Output file for EBS analysis (supports .json, .yaml, .csv) |
--tag-key |
TEXT |
Filter EBS volumes by tag key (e.g., Environment) |
--tag-value |
TEXT |
Filter EBS volumes by tag value (requires --tag-key) |
costops pricing¶
Get AWS pricing information for services.
| Option | Value | Description |
|---|---|---|
--service |
TEXT |
Specific AWS service to get pricing for (e.g., AmazonEC2, AmazonS3) |
--output-dir |
TEXT |
Output directory for pricing data (default: ./aws_pricing_ |
--list-services |
flag | List all available AWS services for pricing |
--format |
json | summary |
Output format: json (raw data) or summary (processed) (default: summary) |
costops spot-analysis¶
Analyze previously collected spot pricing data to find cheapest options.
| Option | Value | Description |
|---|---|---|
--top-n |
INTEGER |
Number of top cheapest instances to show (default: 10) |
--estimate-period |
INTEGER |
Period in days for cost estimation (default: 30) |
--instance-type-filter |
TEXT |
Filter results by instance type pattern (e.g., 'm5', 'c5.large') |
--region-filter |
TEXT |
Filter results by region |
--output-file |
TEXT |
Output file for analysis results (supports .json, .yaml, .csv) |
costops spot-pricing¶
Collect and analyze EC2 spot pricing data across regions.
| Option | Value | Description |
|---|---|---|
--region |
TEXT |
Specific AWS region to collect spot pricing for |
--all-regions |
flag | Collect spot pricing data from all regions |
--time-range |
INTEGER |
Time range in hours for spot pricing data (default: 24) |
--instance-types |
TEXT |
Comma-separated list of instance types to include (e.g., m5.large,c5.xlarge) |
--product-description |
TEXT |
Product description filter (default: Linux/UNIX) |
--output-dir |
TEXT |
Output directory for spot pricing data (default: ./spot_pricing_ |
--output-file |
TEXT |
Output file for consolidated spot pricing analysis (supports .json, .yaml, .csv) |
costops usage-metrics¶
Get detailed usage metrics for a specific AWS service.
| Option | Value | Description |
|---|---|---|
--months |
INTEGER |
Number of months to analyze (default: 3) |
--metric-type |
cost | usage | both |
Type of metrics to retrieve (default: both) |
--group-by |
usage_type | region | instance_type | operation |
Group metrics by dimension (default: usage_type) |
--output-file |
TEXT |
Output file for usage metrics (supports .json, .yaml, .csv) |
Examples¶
# Spend by service over the last three months
aws-cloud-utilities costops cost-analysis
# Twelve months, grouped by region
aws-cloud-utilities costops cost-analysis --months 12 --group-by region --output-file spend.csv
# Drill into one service
aws-cloud-utilities costops usage-metrics AmazonEC2 --months 6 --group-by instance_type
# EBS volumes worth changing, across every region
aws-cloud-utilities costops ebs-optimization --all-regions --include-cost-estimates
# Only gp2 volumes tagged for production
aws-cloud-utilities costops ebs-optimization --all-regions --volume-type gp2 \
--tag-key Environment --tag-value production
# Pricing data
aws-cloud-utilities costops pricing --list-services
aws-cloud-utilities costops pricing --service AmazonEC2 --format summary
# Collect spot pricing, then analyze the collected data
aws-cloud-utilities costops spot-pricing --all-regions --output-dir ./spot-data
aws-cloud-utilities costops spot-analysis ./spot-data --top-n 20 --instance-type-filter m5
Spot pricing is two steps¶
spot-pricing collects raw data and writes it to a directory. spot-analysis reads that directory and
ranks the results. Run them in order:
aws-cloud-utilities costops spot-pricing --all-regions --output-dir ./spot-data
aws-cloud-utilities costops spot-analysis ./spot-data --top-n 10 --estimate-period 30
Notes¶
Cost Explorer charges roughly $0.01 per API request. cost-analysis and usage-metrics make several
requests each, so a loop over many services adds up.
--tag-key and --tag-value on ebs-optimization filter by volume tags; --tag-value requires
--tag-key.
Related¶
- Billing Commands - set up the CUR that backs deeper cost analysis
- DynamoDB Commands - table-level capacity cost analysis
- Inventory Commands - find the resources behind the spend
- Support Commands - Trusted Advisor cost-savings checks