$npx -y skills add BagelHole/DevOps-Security-Agent-Skills --skill aws-cost-optimizationReduce AWS spend with rightsizing, autoscaling, commitment planning, and storage lifecycle policies. Use when running FinOps reviews, lowering cloud bills, or improving cost-per-request metrics.
| 1 | # AWS Cost Optimization |
| 2 | |
| 3 | Apply practical FinOps controls to reduce AWS spend without sacrificing reliability or performance. |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | - Monthly AWS bill spikes unexpectedly or exceeds budget thresholds |
| 8 | - Preparing cost reviews with engineering and finance teams |
| 9 | - Rightsizing EC2, RDS, EKS, or Lambda workloads after load testing |
| 10 | - Choosing between Savings Plans, Reserved Instances, or on-demand pricing |
| 11 | - Setting up automated budget alerts and anomaly detection |
| 12 | - Cleaning up unused resources (unattached EBS, idle load balancers, old snapshots) |
| 13 | - Optimizing data transfer costs across regions and AZs |
| 14 | |
| 15 | ## Prerequisites |
| 16 | |
| 17 | - AWS CLI v2 installed and configured (`aws configure`) |
| 18 | - IAM permissions: `ce:*`, `budgets:*`, `ec2:Describe*`, `cloudwatch:PutMetricAlarm`, `s3:PutLifecycleConfiguration` |
| 19 | - Cost Explorer enabled in the AWS billing console (takes 24 hours to populate) |
| 20 | - Cost allocation tags activated in the Billing console |
| 21 | |
| 22 | ## Cost Review Workflow |
| 23 | |
| 24 | 1. Tag every resource by team, service, environment, and cost center. |
| 25 | 2. Enable Cost Explorer and activate Cost and Usage Reports (CUR) to S3. |
| 26 | 3. Identify top spend drivers by service, account, and tag. |
| 27 | 4. Rightsize underutilized compute and storage based on CloudWatch metrics. |
| 28 | 5. Apply commitment discounts (Savings Plans or RIs) for stable baseline usage. |
| 29 | 6. Set budgets, anomaly alerts, and build KPI dashboards. |
| 30 | 7. Review monthly and iterate. |
| 31 | |
| 32 | ## Cost Explorer CLI Commands |
| 33 | |
| 34 | ```bash |
| 35 | # Get cost and usage for the last 30 days grouped by service |
| 36 | aws ce get-cost-and-usage \ |
| 37 | --time-period Start=2026-02-01,End=2026-03-01 \ |
| 38 | --granularity MONTHLY \ |
| 39 | --metrics "BlendedCost" "UnblendedCost" "UsageQuantity" \ |
| 40 | --group-by Type=DIMENSION,Key=SERVICE |
| 41 | |
| 42 | # Get cost forecast for the next 30 days |
| 43 | aws ce get-cost-forecast \ |
| 44 | --time-period Start=2026-03-24,End=2026-04-24 \ |
| 45 | --metric UNBLENDED_COST \ |
| 46 | --granularity MONTHLY |
| 47 | |
| 48 | # Get cost grouped by a specific tag (e.g., team) |
| 49 | aws ce get-cost-and-usage \ |
| 50 | --time-period Start=2026-02-01,End=2026-03-01 \ |
| 51 | --granularity MONTHLY \ |
| 52 | --metrics "UnblendedCost" \ |
| 53 | --group-by Type=TAG,Key=team |
| 54 | |
| 55 | # Get rightsizing recommendations for EC2 |
| 56 | aws ce get-rightsizing-recommendation \ |
| 57 | --service "AmazonEC2" \ |
| 58 | --configuration '{"RecommendationTarget":"SAME_INSTANCE_FAMILY","BenefitsConsidered":true}' |
| 59 | |
| 60 | # Get Savings Plans purchase recommendation |
| 61 | aws ce get-savings-plans-purchase-recommendation \ |
| 62 | --savings-plans-type COMPUTE_SP \ |
| 63 | --term-in-years ONE_YEAR \ |
| 64 | --payment-option NO_UPFRONT \ |
| 65 | --lookback-period-in-days SIXTY_DAYS |
| 66 | |
| 67 | # Get Savings Plans utilization |
| 68 | aws ce get-savings-plans-utilization \ |
| 69 | --time-period Start=2026-02-01,End=2026-03-01 \ |
| 70 | --granularity MONTHLY |
| 71 | |
| 72 | # Get Reserved Instance utilization |
| 73 | aws ce get-reservation-utilization \ |
| 74 | --time-period Start=2026-02-01,End=2026-03-01 \ |
| 75 | --granularity MONTHLY |
| 76 | ``` |
| 77 | |
| 78 | ## Budget Alerts |
| 79 | |
| 80 | ```bash |
| 81 | # Create a monthly cost budget with email alert at 80% and 100% |
| 82 | aws budgets create-budget \ |
| 83 | --account-id 123456789012 \ |
| 84 | --budget '{ |
| 85 | "BudgetName": "monthly-total", |
| 86 | "BudgetLimit": {"Amount": "5000", "Unit": "USD"}, |
| 87 | "TimeUnit": "MONTHLY", |
| 88 | "BudgetType": "COST", |
| 89 | "CostFilters": {}, |
| 90 | "CostTypes": { |
| 91 | "IncludeTax": true, |
| 92 | "IncludeSubscription": true, |
| 93 | "UseBlended": false |
| 94 | } |
| 95 | }' \ |
| 96 | --notifications-with-subscribers '[ |
| 97 | { |
| 98 | "Notification": { |
| 99 | "NotificationType": "ACTUAL", |
| 100 | "ComparisonOperator": "GREATER_THAN", |
| 101 | "Threshold": 80, |
| 102 | "ThresholdType": "PERCENTAGE" |
| 103 | }, |
| 104 | "Subscribers": [{"SubscriptionType": "EMAIL", "Address": "finops@example.com"}] |
| 105 | }, |
| 106 | { |
| 107 | "Notification": { |
| 108 | "NotificationType": "ACTUAL", |
| 109 | "ComparisonOperator": "GREATER_THAN", |
| 110 | "Threshold": 100, |
| 111 | "ThresholdType": "PERCENTAGE" |
| 112 | }, |
| 113 | "Subscribers": [{"SubscriptionType": "EMAIL", "Address": "finops@example.com"}] |
| 114 | } |
| 115 | ]' |
| 116 | |
| 117 | # List all budgets |
| 118 | aws budgets describe-budgets --account-id 123456789012 |
| 119 | |
| 120 | # Enable Cost Anomaly Detection monitor for all services |
| 121 | aws ce create-anomaly-monitor \ |
| 122 | --anomaly-monitor '{ |
| 123 | "MonitorName": "all-services", |
| 124 | "MonitorType": "DIMENSIONAL", |
| 125 | "MonitorDimension": "SERVICE" |
| 126 | }' |
| 127 | |
| 128 | # Create anomaly subscription (alert when impact > $50) |
| 129 | aws ce create-anomaly-subscription \ |
| 130 | --anomaly-subscription '{ |
| 131 | "SubscriptionName": "cost-alerts", |
| 132 | "MonitorArnList": ["arn:aws:ce::123456789012:anomalymonitor/monitor-id"], |
| 133 | "Subscribers": [{"Type": "EMAIL", "Address": "finops@example.com"}], |
| 134 | "Threshold": 50, |
| 135 | "Frequency": "DAILY" |
| 136 | }' |
| 137 | ``` |
| 138 | |
| 139 | ## CloudWatch Cost Alarm |
| 140 | |
| 141 | ```bash |
| 142 | # Create alarm for estimated charges exceeding $4000 |
| 143 | aws cloudwatch put-metric-alarm \ |
| 144 | --alar |