Cloud Computing Tutorial · Integration and Operations · Lesson 21 of 24
Cost Management (FinOps)
See where money goes with tags and cost allocation, set budgets and anomaly alerts, and find the usual savings.
Visibility first
You can't optimise what you can't attribute. Tag every resource with owner, team, environment and service (AWS cost allocation tags, Azure tags, Google Cloud labels), enforce it with policies, and review costs per team.
from collections import defaultdict
line_items = [
{"service": "EC2", "cost": 4200, "tags": {"team": "payments", "env": "prod"}},
{"service": "RDS", "cost": 2600, "tags": {"team": "payments", "env": "prod"}},
{"service": "EC2", "cost": 1900, "tags": {"team": "search", "env": "dev"}},
{"service": "S3", "cost": 700, "tags": {}},
{"service": "NAT Gateway", "cost": 1300, "tags": {"team": "search", "env": "prod"}},
]
by_team = defaultdict(float)
for item in line_items:
by_team[item["tags"].get("team", "UNTAGGED")] += item["cost"]
total = sum(by_team.values())
for team, cost in sorted(by_team.items(), key=lambda kv: -kv[1]):
print(f"{team:9} ${cost:7,.0f} {cost / total:4.0%}")
Output
payments $ 6,800 64% search $ 3,200 30% UNTAGGED $ 700 7%
Guardrails
- Budgets with alerts at 50/80/100% per account or team (AWS Budgets, Azure Cost Management budgets, Google Cloud Budgets).
- Anomaly detection for sudden jumps (a runaway job, a leaked key mining crypto).
- Development environments that shut down at night.
The usual savings
| Area | Typical fix |
|---|---|
| Idle and oversized resources | Rightsize from metrics; delete unattached disks, old snapshots and idle IPs |
| Steady compute | Savings plans / reservations / committed use |
| Interruptible work | Spot capacity |
| Storage | Lifecycle rules, cheaper classes, log retention |
| Data transfer | Keep chatty services in one zone where safe, VPC endpoints instead of NAT, CDN caching |
| Architecture | Arm-based instances, serverless for spiky workloads |
FinOps is a team practice: engineers see the cost of what they build, finance sees forecasts, and both decide trade-offs together.
Test yourself
What should you set up first to understand which team spends what?
Consistent tags with cost allocationSpot instancesA bigger budgetMulti-region deployment
Show answer
Answer: Consistent tags with cost allocation
Tags turn a single bill into costs per team, service and environment.