Optimizing Cloud Costs
Overview
Analyze cloud spending across AWS, GCP, and Azure to identify waste, recommend rightsizing, and generate cost-saving configurations. Covers reserved instances, spot/preemptible workloads, storage tiering, idle resource cleanup, and budget alerting using cloud-native cost management APIs.
Prerequisites
- Cloud provider CLI authenticated with billing/cost-explorer read access
- AWS:
ce:GetCostAndUsage, ec2:DescribeInstances, cloudwatch:GetMetricData permissions
- GCP: Billing Account Viewer and Compute Viewer roles
- Azure: Cost Management Reader role
- Access to current infrastructure-as-code (Terraform, CloudFormation) for rightsizing changes
- At least 30 days of billing data for meaningful analysis
Instructions
- Pull current cost data using cloud cost APIs (
aws ce get-cost-and-usage, gcloud billing budgets list)
- Identify the top 10 cost drivers by service, region, and resource tag
- Detect idle resources: instances with < 5% average CPU over 14 days, unattached EBS volumes, unused Elastic IPs, orphaned snapshots
- Recommend rightsizing: compare instance utilization against available instance types and suggest downsizing
- Evaluate reserved instance or savings plan coverage against on-demand spend; recommend commitments for steady-state workloads
- Identify spot/preemptible candidates: stateless, fault-tolerant workloads (batch jobs, CI runners, dev environments)
- Review storage costs: recommend S3 Intelligent-Tiering, lifecycle policies for infrequent access, or Glacier for archives
- Generate Terraform/IaC changes to implement approved optimizations
- Set up budget alerts with thresholds at 50%, 80%, and 100% of monthly budget
- Create a cost optimization report summarizing findings, savings estimates, and implementation priority
Output
- Cost analysis report with per-service breakdown and savings recommendations
- Terraform/CloudFormation changes for rightsizing and reserved instance purchases
- S3 lifecycle policy configurations for storage tiering
- Budget alert configurations (CloudWatch, GCP Budget, Azure Cost Alerts)
- Cleanup scripts for idle resources (with dry-run mode for safety)
Error Handling
| Error |
Cause |
Solution |
Access Denied on Cost Explorer API |
Missing ce:* IAM permissions |
Attach the AWSBillingReadOnlyAccess managed policy to the IAM user/role |
No billing data available |
Account is too new or cost export not enabled |
Enable Cost Explorer (takes 24h to populate) or set up CUR (Cost and Usage Report) |
Rightsizing recommendation breaks workload |
Instance too small for peak load |
Base sizing on P95 utilization, not average; keep a 20% headroom buffer |
Spot instance terminated mid-job |
Spot capacity reclaimed by provider |
Use spot fleet with diversified instance types and implement checkpointing |
Budget alert not firing |
SNS topic or notification channel misconfigured |
Verify SNS subscription is confirmed and test with a low threshold |
Examples
- "Analyze AWS costs for the last 3 months, identify the top waste areas, and generate a cleanup script for unattached EBS volumes and unused Elastic IPs."
- "Compare on-demand EC2 spend against Savings Plans pricing and recommend 1-year commitments for steady-state workloads."
- "Create S3 lifecycle policies to move objects older than 90 days to Glacier and delete after 365 days across all buckets tagged
env:production."
Resources
1---
2name: optimizing-cloud-costs
3description: |
4 Execute use when you need to work with cloud cost optimization.
5 This skill provides cost analysis and optimization with comprehensive guidance and automation.
6 Trigger with phrases like "optimize costs", "analyze spending",
7 or "reduce costs".
8
9allowed-tools: Read, Write, Edit, Grep, Glob, Bash(aws:*), Bash(gcloud:*), Bash(az:*)
10version: 1.0.0
11author: Jeremy Longshore <jeremy@intentsolutions.io>
12license: MIT
13compatible-with: claude-code, codex, openclaw
14metadata:
15 source: https://skillmd.com/skills/micsapp/optimizing-cloud-costs
16---
17
18# Optimizing Cloud Costs
19
20## Overview
21
22Analyze cloud spending across AWS, GCP, and Azure to identify waste, recommend rightsizing, and generate cost-saving configurations. Covers reserved instances, spot/preemptible workloads, storage tiering, idle resource cleanup, and budget alerting using cloud-native cost management APIs.
23
24## Prerequisites
25
26- Cloud provider CLI authenticated with billing/cost-explorer read access
27- AWS: `ce:GetCostAndUsage`, `ec2:DescribeInstances`, `cloudwatch:GetMetricData` permissions
28- GCP: Billing Account Viewer and Compute Viewer roles
29- Azure: Cost Management Reader role
30- Access to current infrastructure-as-code (Terraform, CloudFormation) for rightsizing changes
31- At least 30 days of billing data for meaningful analysis
32
33## Instructions
34
351. Pull current cost data using cloud cost APIs (`aws ce get-cost-and-usage`, `gcloud billing budgets list`)
362. Identify the top 10 cost drivers by service, region, and resource tag
373. Detect idle resources: instances with < 5% average CPU over 14 days, unattached EBS volumes, unused Elastic IPs, orphaned snapshots
384. Recommend rightsizing: compare instance utilization against available instance types and suggest downsizing
395. Evaluate reserved instance or savings plan coverage against on-demand spend; recommend commitments for steady-state workloads
406. Identify spot/preemptible candidates: stateless, fault-tolerant workloads (batch jobs, CI runners, dev environments)
417. Review storage costs: recommend S3 Intelligent-Tiering, lifecycle policies for infrequent access, or Glacier for archives
428. Generate Terraform/IaC changes to implement approved optimizations
439. Set up budget alerts with thresholds at 50%, 80%, and 100% of monthly budget
4410. Create a cost optimization report summarizing findings, savings estimates, and implementation priority
45
46## Output
47
48- Cost analysis report with per-service breakdown and savings recommendations
49- Terraform/CloudFormation changes for rightsizing and reserved instance purchases
50- S3 lifecycle policy configurations for storage tiering
51- Budget alert configurations (CloudWatch, GCP Budget, Azure Cost Alerts)
52- Cleanup scripts for idle resources (with dry-run mode for safety)
53
54## Error Handling
55
56| Error | Cause | Solution |
57|-------|-------|---------|
58| `Access Denied on Cost Explorer API` | Missing `ce:*` IAM permissions | Attach the `AWSBillingReadOnlyAccess` managed policy to the IAM user/role |
59| `No billing data available` | Account is too new or cost export not enabled | Enable Cost Explorer (takes 24h to populate) or set up CUR (Cost and Usage Report) |
60| `Rightsizing recommendation breaks workload` | Instance too small for peak load | Base sizing on P95 utilization, not average; keep a 20% headroom buffer |
61| `Spot instance terminated mid-job` | Spot capacity reclaimed by provider | Use spot fleet with diversified instance types and implement checkpointing |
62| `Budget alert not firing` | SNS topic or notification channel misconfigured | Verify SNS subscription is confirmed and test with a low threshold |
63
64## Examples
65
66- "Analyze AWS costs for the last 3 months, identify the top waste areas, and generate a cleanup script for unattached EBS volumes and unused Elastic IPs."
67- "Compare on-demand EC2 spend against Savings Plans pricing and recommend 1-year commitments for steady-state workloads."
68- "Create S3 lifecycle policies to move objects older than 90 days to Glacier and delete after 365 days across all buckets tagged `env:production`."
69
70## Resources
71
72- AWS Cost Explorer: https://docs.aws.amazon.com/cost-management/latest/userguide/ce-what-is.html
73- GCP Cost Management: https://cloud.google.com/billing/docs/how-to/budgets
74- Azure Cost Management: https://learn.microsoft.com/en-us/azure/cost-management-billing/
75- FinOps Foundation: https://www.finops.org/framework/