Lesson 5 of 11 · 11 min · Cloud basics
Cloud cost basics
What you will learn
- How cloud billing works and the dimensions you are charged for
- The usual causes of surprise bills
- Tagging, budgets, alerts and cost visibility
- Practical savings: right-sizing, scheduling, commitments, Spot, storage and transfer
- A basic FinOps routine
In simple words
A cloud bill is like an electricity bill with hundreds of meters: each machine, each gigabyte stored, each gigabyte sent out. Small things left running add up quietly. This lesson shows what you are charged for, what causes surprise bills, and the habits that keep costs under control.
Words to know
- Pay as you go: you are billed for what you use, by the hour, second or gigabyte.
- Tag: a label on a resource, such as
team: payments, so you can see who spent what. - Budget alert: a message sent when spending passes a limit that you set.
- Right-sizing: choosing a machine that fits the real need instead of an oversized one.
How you are billed
The cloud turns infrastructure into metered usage. Every service charges along several dimensions:
| Service | Typical dimensions |
|---|---|
| Compute (EC2, Fargate) | instance-hours (per second), vCPU and GB-hours |
| Serverless (Lambda) | requests, execution time × memory |
| Storage (S3) | GB-months stored, requests, retrieval, data transfer out |
| Block storage (EBS) | GB-months provisioned (even if empty), IOPS/throughput, snapshots |
| Database (RDS) | instance-hours, storage GB, IOPS, backup storage beyond free, Multi-AZ doubles instance cost |
| Load balancer | hours + capacity units (traffic, connections) |
| NAT gateway | hours + per-GB processed |
| Network | data transfer out to the internet, between regions and often between zones |
| Monitoring and logs | metrics, log ingestion and storage |
Two facts shape everything: you pay for what is provisioned, not what is used (a stopped instance still pays for its EBS volume; an idle database costs the same as a busy one), and small unit prices multiply (Rs 0.x per GB across terabytes, or per hour across a month: 730 hours).
Illustrative arithmetic (made-up round numbers, not real prices): an instance at 5 rupees per hour costs 5 × 730 = 3,650 rupees a month if left running; 8 hours a day on weekdays only is about 5 × 8 × 22 = 880 rupees. Scheduling non-production environments off outside working hours saves around three quarters of their compute cost.
The usual suspects behind a high bill
- Idle or forgotten resources: instances, databases, load balancers and Elastic IPs nobody uses; unattached EBS volumes; old snapshots; test environments left on. Free-tier accounts are surprised by these first.
- Oversized resources: big instances at 5% CPU; Multi-AZ everywhere including dev.
- NAT gateway data processing: every gigabyte that private instances send to the internet (including to S3 and ECR if you don't use endpoints) pays a per-GB processing fee on top of the hourly charge. Fix with VPC gateway endpoints for S3/DynamoDB (free) and interface endpoints for other services.
- Data transfer: traffic out to the internet, cross-region replication and, often overlooked, cross-AZ traffic (microservices chattering between zones, load balancers sending to targets in other zones). Use a CDN, keep chatty services in the same zone where reasonable, compress.
- Logs and metrics: debug logging at high volume into CloudWatch Logs (ingestion is priced per GB) and high-cardinality custom metrics.
- Storage that only grows: S3 without lifecycle rules, old versions, snapshots, backups; logs kept forever.
- On-demand pricing for steady workloads (commitments save a lot).
- Public IPv4 addresses are now billed per hour; release unused ones.
- Autoscaling that never scales down, or a runaway loop, or a mining-malware compromise (unusual compute spikes: set alerts).
- Data egress from a cloud you want to leave: lock-in has a price.
Alerts and guard rails
Set these up before you launch anything on a new account:
- Budgets with alerts: a monthly budget with notifications at 50%, 80% and 100% of actual and forecasted spend, to email and chat. (AWS Budgets, Azure Budgets, GCP budgets.)
- Anomaly detection: AWS Cost Anomaly Detection flags unusual daily spend.
- Billing alarms for free-tier accounts and for students experimenting: a runaway lab can cost real money.
- Service quotas and limits so a mistake cannot create 500 instances.
- Least privilege: fewer people able to create expensive resources.
- Automatic clean-up of sandboxes (tags with an expiry date plus a scheduled job; tools like cloud-nuke for dev accounts).
Saving money
Work in this order: remove waste, right-size, schedule, then commit.
- Delete what is unused: find idle resources (Trusted Advisor, Compute Optimizer, Azure Advisor, GCP Recommender), unattached volumes, old snapshots and AMIs, empty load balancers.
- Right-size: pick instance sizes from measured CPU/memory (CloudWatch with the agent; Compute Optimizer recommendations). Move to current-generation and Graviton/ARM types (often 20-40% better price/performance). Use gp3 instead of gp2 volumes. Fargate task sizes match real use.
- Schedule non-production to stop evenings and weekends; scale dev/test databases to zero or snapshot-and-delete.
- Autoscale instead of provisioning for peak all day; use serverless for spiky loads.
- Commit for steady usage: Savings Plans (flexible commitment per hour of spend, applies across instance families and Fargate/Lambda) or Reserved Instances for 1-3 years. Cover only the stable baseline (say 60-70% of steady usage), and only after right-sizing.
- Use Spot for fault-tolerant workloads (batch, CI, stateless workers) with diversified instance types and interruption handling.
- Storage: lifecycle rules to cheaper classes, expire old versions and logs, Intelligent-Tiering for unpredictable access, compress, avoid duplicates.
- Network: CDN to cut egress and origin load; VPC endpoints; same-zone traffic for chatty pairs; avoid pulling images through NAT (ECR endpoints).
- Reduce observability waste: set log retention (not "never expire"), sample traces, drop debug logs in production.
- Architect for cost: managed services often cost more per unit but less in people time; serverless is cheap at low volume and expensive at constant high volume. Consider total cost, not only the cloud bill.
A monthly routine (FinOps in practice)
FinOps is the practice of engineers, finance and product managing cloud spend together. A lightweight routine for a small team:
- Review last month's bill by service and tag; explain the top five items.
- Check anomalies, untagged spend and forecast versus budget.
- Act on the top recommendations (right-size, delete, schedule).
- Re-evaluate commitments quarterly.
- Show each team its own cost (showback) so ownership is clear, and include cost in design reviews ("what will this cost at 10× traffic?").
- Estimate cost in pull requests (Infracost) for infrastructure changes.
Use the provider's pricing calculator before building, and run real load to get actual numbers.
Free tiers and learning safely
AWS offers a free tier (12-month and always-free allowances) and credits for new accounts; Google Cloud and Azure have credits and always-free products; Oracle's always-free VMs are generous. Learning safely: create a budget alert first, use one region, tag everything with Owner=you and an expiry, prefer services you understand, and run terraform destroy (or delete) at the end of every session. Know that some "free" items still bill when you exceed limits or use extras (NAT gateways and public IPv4 addresses are common first-bill surprises).
Common mistakes
- No budget or alerts until the first shock.
- Treating the cloud as a fixed-cost data centre (leaving everything on).
- Untagged resources nobody can attribute.
- Committing before right-sizing.
- Ignoring data transfer, NAT and logging costs in designs.
- Multi-AZ, large instances and high availability in dev.
- Unbounded retention for logs, snapshots and versions.
- Optimising a small line item while a big one is ignored.
Try it yourself
- Set up a monthly budget with email alerts at 50%, 80% and 100% on a sandbox account.
- Tag a few resources and activate the tags in billing; then group Cost Explorer by tag.
- Pick one non-production environment and calculate the saving from running it only on working hours.
- Find your three largest cost items and write one action for each.
Check yourself
Why can a stopped EC2 instance still cost money?
Its attached EBS volumes (and any Elastic IPs and snapshots) are still provisioned and billed; only the instance compute charge stops.
What often causes unexpectedly high NAT gateway bills?
Large volumes of traffic from private subnets to the internet or to AWS services through the NAT, which charges per GB processed. Use VPC endpoints and caches to avoid it.
What is the correct order for cost optimisation?
Delete waste, right-size, schedule/autoscale, then buy commitments (Savings Plans/Reserved) for the steady baseline; use Spot where interruption is acceptable.
Why are tags important for cost management?
They attribute spend to projects, teams and environments so you can see who owns it and where to optimise; untagged resources can't be allocated.
Interview questions
How would you cut a startup's monthly AWS bill by 30%?
Analyse by service and tag; remove idle resources; right-size instances and databases; schedule non-production off-hours; buy a Savings Plan for the stable baseline; move to Graviton and gp3; add S3 lifecycle rules and log retention; fix NAT/data-transfer hot spots with VPC endpoints and a CDN; set budgets and anomaly detection so it stays down.
What is FinOps?
A practice of collaborative financial accountability for cloud spend, combining engineering, finance and product to make cost visible, optimise continuously and make trade-offs between speed, quality and cost.
Savings Plans versus Spot?
Savings Plans are a commitment for lower prices on steady usage with no interruption; Spot offers the deepest discounts for spare capacity that can be reclaimed with short notice, suited to fault-tolerant workloads.
Summary
- You pay for provisioned capacity and metered usage; idle resources, NAT/data transfer, logs and unbounded storage are common bill drivers.
- Tag everything, separate accounts, and set budgets, alerts and anomaly detection before launching.
- Optimise in order: delete waste, right-size, schedule/autoscale, commit, use Spot where suitable.
- Make cost a routine: monthly review, showback to teams, estimates in design and pull requests.
Going deeper
- AWS Well-Architected: cost optimization pillar: design principles and practices.
- AWS Budgets: setting budgets and alerts.
- AWS Cost Explorer: analysing costs.
- AWS Pricing Calculator: estimating architectures before you build.
- FinOps Foundation: the practice and its principles.
See how much of this you can explain
A free mock interview asks you new questions on Cloud platforms and AWS fundamentals for DevOps Engineer and scores every answer, with what to fix.