AWS for DevOps — Cost Explorer & Budgets

2 minute read

14.2 — Cost Explorer & Budgets

You can’t optimize what you can’t see. Cost Explorer shows where your money goes. Budgets alert you before you overspend.

Cost Explorer

Cost Explorer provides visual cost analysis. Enable it once, and it retains 13 months of data.

# Get last month's cost by service
$ aws ce get-cost-and-usage \
    --time-period Start=2026-03-01,End=2026-03-31 \
    --granularity MONTHLY \
    --metrics BlendedCost \
    --group-by Type=DIMENSION,Key=SERVICE
{
    "ResultsByTime": [{
        "TimePeriod": {"Start": "2026-03-01", "End": "2026-03-31"},
        "Groups": [
            {"Keys": ["Amazon EC2"], "Metrics": {"BlendedCost": {"Amount": "542.30"}}},
            {"Keys": ["Amazon RDS"], "Metrics": {"BlendedCost": {"Amount": "198.50"}}},
            {"Keys": ["Amazon S3"], "Metrics": {"BlendedCost": {"Amount": "45.20"}}},
            {"Keys": ["AWS Lambda"], "Metrics": {"BlendedCost": {"Amount": "12.80"}}}
        ]
    }]
}

# Get daily cost trend
$ aws ce get-cost-and-usage \
    --time-period Start=2026-03-01,End=2026-03-31 \
    --granularity DAILY \
    --metrics BlendedCost

# Get cost by tag (Environment)
$ aws ce get-cost-and-usage \
    --time-period Start=2026-03-01,End=2026-03-31 \
    --granularity MONTHLY \
    --metrics BlendedCost \
    --group-by Type=TAG,Key=Environment

Cost Forecast

# Forecast next month's cost
$ aws ce get-cost-forecast \
    --time-period Start=2026-04-01,End=2026-04-30 \
    --metric BLENDED_COST \
    --granularity MONTHLY
{
    "Total": {
        "Amount": "825.40",
        "Unit": "USD"
    },
    "ForecastResultsByTime": [...]
}

AWS Budgets

Budgets alert you when costs exceed (or are forecasted to exceed) a threshold.

# Create a monthly budget of $1000
$ aws budgets create-budget \
    --account-id 123456789012 \
    --budget '{
      "BudgetName": "monthly-total",
      "BudgetLimit": {"Amount": "1000", "Unit": "USD"},
      "TimeUnit": "MONTHLY",
      "BudgetType": "COST"
    }' \
    --notifications-with-subscribers '[
      {
        "Notification": {
          "NotificationType": "ACTUAL",
          "ComparisonOperator": "GREATER_THAN",
          "Threshold": 80,
          "ThresholdType": "PERCENTAGE"
        },
        "Subscribers": [{
          "SubscriptionType": "EMAIL",
          "Address": "devops@example.com"
        }]
      },
      {
        "Notification": {
          "NotificationType": "FORECASTED",
          "ComparisonOperator": "GREATER_THAN",
          "Threshold": 100,
          "ThresholdType": "PERCENTAGE"
        },
        "Subscribers": [{
          "SubscriptionType": "EMAIL",
          "Address": "devops@example.com"
        }]
      }
    ]'
Budget Threshold Notification
Total monthly 80% actual Email + Slack
Total monthly 100% forecasted Email + PagerDuty
Per-service (EC2) 90% actual Email
Per-environment (production) 80% actual Email
Per-team (tag-based) 80% actual Team Slack channel

Cost Anomaly Detection

# Create a cost anomaly monitor
$ aws ce create-anomaly-monitor \
    --anomaly-monitor '{
      "MonitorName": "service-monitor",
      "MonitorType": "DIMENSIONAL",
      "MonitorDimension": "SERVICE"
    }'

# Create a subscription for alerts
$ aws ce create-anomaly-subscription \
    --anomaly-subscription '{
      "SubscriptionName": "cost-anomaly-alerts",
      "MonitorArnList": ["arn:aws:ce::123456789012:anomalymonitor/monitor-abc123"],
      "Subscribers": [{"Address": "devops@example.com", "Type": "EMAIL"}],
      "Threshold": 50,
      "Frequency": "IMMEDIATE"
    }'

Common Mistakes

Mistake Why It Hurts Fix
No budget alerts Surprise bill at month end Set budget at 80% and 100% thresholds
Only total budget Can’t find which service spiked Create per-service and per-tag budgets
No forecasted alerts React too late Alert when forecast exceeds budget
Not using Cost Anomaly Detection Miss sudden cost spikes Enable anomaly detection

Quick Reference

Task Command
Get cost by service aws ce get-cost-and-usage --time-period Start=...,End=... --granularity MONTHLY --metrics BlendedCost --group-by Type=DIMENSION,Key=SERVICE
Get cost forecast aws ce get-cost-forecast --time-period Start=...,End=... --metric BLENDED_COST --granularity MONTHLY
Create budget aws budgets create-budget --account-id ID --budget '...' --notifications-with-subscribers '...'
List budgets aws budgets describe-budgets --account-id ID

Next → Reserved & Savings Plans

Updated: