Cloud cost
About this lesson
A cloud bill is a sum of meters, each rate × quantity, and a server is billed for every hour it is switched on, busy or idle. Follow one month's bill, written as a short Python program: four always-on web servers and two idle test servers cost $438. Tag the costs to find their owners, rightsize, switch off what nobody uses at night and commit to the steady part, and the same service costs $146.20. Then keep it there with a budget alert and a cost per order.
Every resource has a meter
A cloud bill is a sum of meters, each rate × quantity. Servers are billed per hour while switched on, busy or idle. Storage is billed per GB-month, data sent out per GB. This Python function prices servers.
bill = Σ rate × quantity
servers $ per server-hour (on = billed)
storage $ per GB-month
egress $ per GB sent out
def cost(n, hours, rate=0.10):
return round(n * hours * rate, 2)Read the lesson step by step
Every resource has a meter
A cloud bill is a sum of meters, each rate × quantity. Servers are billed per hour while switched on, busy or idle. Storage is billed per GB-month, data sent out per GB. This Python function prices servers.
bill = Σ rate × quantity servers $ per server-hour (on = billed) storage $ per GB-month egress $ per GB sent out def cost(n, hours, rate=0.10): return round(n * hours * rate, 2)Always-on web servers
Four web servers run all month. An average month has 730 hours (365 × 24 ÷ 12). At an example rate of $0.10 per server-hour, cost(4, 730) is 4 × 730 × 0.10 = $292.
web = cost(4, 730) 4 servers × 730 h × $0.10 = $292.00 730 h = 365 days × 24 h ÷ 12 months bill so far: $292.00Idle test servers
Two test (dev) servers also run 730 hours: cost(2, 730) = $146. Nobody uses them at night or at weekends, but switched on means billed. The month comes to $438.
dev = cost(2, 730) 2 servers × 730 h × $0.10 = $146.00 used: working hours only billed: every hour they are on bill: $438.00 a monthTag to find the owner
Who spends what? Cost allocation tags, labels such as env=prod and env=dev, mark each resource. The bill then splits by tag: dev is $146 of $438, a third, for servers idle most of the week.
resource tag $/month web × 4 env=prod 292.00 dev × 2 env=dev 146.00 dev = 146 / 438 = 1/3 of the bill tags must be activated for billingRightsize the web tier
Monitoring shows the four web servers average 20% CPU: more than the load needs. Two servers at 40% still leave headroom. Rightsizing matches capacity to real use: cost(2, 730) = $146, half the web bill.
web = cost(2, 730) before: 4 servers at 20% CPU after: 2 servers at 40% CPU (same load) $292.00 → $146.00 bill: $292.00Switch off when idle
The dev servers are only needed in working hours: 10 hours a day, 22 workdays, 220 hours. A scheduler stops them at night and at weekends. cost(2, 220) = $44 instead of $146.
dev = cost(2, 220) 10 h × 22 workdays = 220 h 2 servers × 220 h × $0.10 = $44.00 stopped servers: no hourly charge (their disks are still billed) bill: $190.00Commit to steady use
The web servers run every hour of every month. Committing to that use for one or three years earns a discount (AWS Savings Plans, Google committed use discounts). At an example 30% off: cost(2, 730, 0.07) = $102.20.
web = cost(2, 730, 0.07) $0.10 × (1 − 0.30) = $0.07 per hour 2 × 730 × $0.07 = $102.20 commit only to the steady base bill: $146.20The new bill
print(web + dev) shows 146.2. The same service now costs $146.20 a month instead of $438: two thirds less. Users see no change; only paid-for idleness was removed.
print(web + dev) 146.2 before $438.00 after $146.20 saved $291.80 (67%)Set a budget and alert
A budget states the expected spend, here $200 a month, with an alert at 80% ($160). Budget tools warn you when actual or forecast cost crosses it. $146.20 is 73%: fine. The old $438 would have tripped it.
budget $200.00 / month alert at 80% = $160.00 (actual or forecast) now $146.20 = 73.1% ok before $438.00 = 219% alertMeasure cost per order
FinOps, the practice of managing cloud spend as a team, tracks unit cost: spend ÷ useful work. With 10,000 orders, $146.20 ÷ 10,000 ≈ 1.5 cents an order. If orders double and the bill does not, each order gets cheaper.
unit cost = spend ÷ useful work $146.20 ÷ 10,000 orders = $0.01462 ≈ 1.5¢ per order was $438.00 ÷ 10,000 = $0.0438
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01A server is switched on all month but busy only in working hours. What are you billed for?
On-demand servers are billed by the hour or second while they run. Idle time costs the same as busy time, which is why switching off unused servers saves money.
02In the example, what does cost(2, 220) return, and why 220?
The default rate is 0.10, so round(2 * 220 * 0.10, 2) is 44.0. 220 hours is 10 hours a day on 22 workdays, the only time the test servers are needed.
03Monitoring shows four web servers averaging 20% CPU. What does rightsizing do?
The same load on half the servers doubles their average CPU to about 40%, which still leaves headroom, and halves that part of the bill.
04When is a commitment discount (Savings Plans, committed use discounts) a good idea?
You pay the commitment even if your usage drops, so commit only to the steady base, such as web servers that run every hour.
05Why track unit cost, such as cost per order?
A rising bill can be fine if orders rise faster. Spend divided by useful work tells you whether growth is efficient; here $146.20 ÷ 10,000 orders is about 1.5 cents an order.
Glossary
- Pay-as-you-go
- Cloud pricing where you pay each meter (server-hours, GB-months, GB sent out) for what you use, with no upfront purchase.
- Server-hour
- One server switched on for one hour, whether it is busy or idle. On-demand servers are billed by the hour or second.
- Cost allocation tag
- A label such as env=dev attached to a resource, so the bill can be split by team, project or environment. On AWS it must be activated for billing.
- Rightsizing
- Matching the number and size of resources to their real use, measured by monitoring (for example CPU), so you stop paying for spare capacity.
- Scheduling
- Stopping resources when nobody needs them, such as test servers at night and at weekends, and starting them again in working hours.
- Commitment discount
- A lower rate in exchange for promising steady use for one or three years: AWS Savings Plans, Google committed use discounts.
- Budget alert
- A spending limit with a warning when actual or forecast cost crosses a threshold, such as 80% of the budget.
- Unit cost
- Spend divided by a unit of useful work, such as cost per order. FinOps uses it to judge whether spending is efficient.
Notes and sources
- The $0.10 per server-hour rate, the 30% discount, the CPU figures, the $200 budget and the 10,000 orders are example numbers. Real prices vary by provider, region and machine type; the arithmetic is exact.
- AWS bills On-Demand EC2 capacity by the hour or second (minimum of 60 seconds); 730 hours is the average month of a 365-day year (365 × 24 ÷ 12). Data coming in from the internet is free on AWS; data going out is charged per GB.
- A stopped instance has no hourly compute charge, but its attached disks (EBS volumes) are still billed, so scheduled dev servers cost a little more than $44 in real life.
- AWS Savings Plans and Google committed use discounts trade a 1- or 3-year commitment for a lower rate (AWS says up to 72% off). You pay the commitment even if usage drops, so commit only to the steady base.
- The code card is real Python 3; it prints 146.2. Each line reassigns web or dev, so the file reads as the story of the bill.
- AWS: Amazon EC2 On-Demand Pricing
- AWS EC2 User Guide: How instance stop and start works (billing while stopped)
- AWS EC2 User Guide: Stop and start Amazon EC2 instances
- AWS Billing: Organizing and tracking costs using cost allocation tags
- AWS: Savings Plans
- Google Cloud: Committed use discounts
- AWS Cost Management: Managing your costs with AWS Budgets
- AWS Compute Optimizer user guide
- AWS Well-Architected Framework: Cost Optimization Pillar
- FinOps Foundation: What is FinOps?
- FinOps Foundation: Unit Economics
- Google SRE book, ch. 6: Monitoring Distributed Systems
- Kubernetes: Resource Management for Pods and Containers
- Python: round()
Quiz Unlocks after the last step.