Course outline · 0% complete

0/27 lessons0%

Course overview →

The four meters

lesson 8-1 · ~9 min · 22/27

An EC2 instance from lesson 3-1 and a Lambda function from lesson 7-1 both sit completely idle for a month.

EC2 bills its full hourly price the whole month, and Lambda bills nothing. EC2 is a rented machine, so the meter runs while it exists. Lambda is rented milliseconds, so the meter runs only while code runs.

That billing difference is the entire economic argument between units 3 and 7, and this unit turns it into estimates you can do on paper.

Everything is one of four meters

AWS has hundreds of services but essentially four meters. For any service, ask which of these it spins:

  1. Compute time: instance-hours (EC2, RDS) or gigabyte-seconds of function runtime (Lambda).
  2. Storage: GB-months held, covering S3, instance disks, and backups. An EC2 instance's disk is a separate service, EBS (Elastic Block Store): network-attached storage volumes billed per GB-month whether the instance is busy or not.
  3. Requests: per-operation charges, tiny but multiplied by millions (S3 requests, Lambda invocations).
  4. Data transfer OUT: bytes leaving AWS to the internet, about $0.09/GB.

Memorize the asymmetries: data IN is free, data OUT costs. Storage is cheap, compute is not. The meter you forget, and the one that has surprised a generation of engineers, is number 4: serve a 1 GB video to 10,000 viewers and the bandwidth alone is about $900, more than every server involved.

the internet uploads, requests, visitors your AWS region EC2, S3, RDS, Lambda data IN: free data OUT: about $0.09 per GB One 1 GB video served to 10,000 viewers is about 10,000 GB out, roughly $900 of bandwidth before a single server is counted.
Meter 4, the asymmetry that surprises people. Bytes arriving cost nothing, and bytes leaving for the internet are billed per gigabyte, so a bandwidth-heavy app can spend more on shipping data than on every server involved.

Estimating a compute charge

Estimating is rate multiplied by time. These scripts track money in hundredths of a cent so that integer arithmetic never rounds anything away. A t3.micro costs $0.0104 per hour, which is rate 104, and a month averages 730 hours.

# prices in hundredths of a cent per hour
ec2_rate=104          # t3.micro: $0.0104/hour
hours=730             # hours in an average month
ec2=$((ec2_rate * hours))
printf 'EC2 t3.micro: $%d.%02d/month\n' $((ec2 / 10000)) $((ec2 % 10000 / 100))

Output

EC2 t3.micro: $7.59/month

The 730 figure is worth memorizing: 365 × 24 / 12, the average month. Using 720 or 744 instead makes estimates disagree with real invoices for no reason.

The printf splits the integer into dollars and cents, since bash has no floating-point arithmetic. Dividing by 10000 gives whole dollars, and % 10000 / 100 gives the cents.

Adding the disk to the estimate

The instance also needs a disk. An 8 GB EBS volume of the default gp3 type costs $0.08 per GB-month, which is rate 800 in these units.

ec2_rate=104
hours=730
ec2=$((ec2_rate * hours))
ebs_rate=800          # gp3 disk: $0.08 per GB-month
disk_gb=8
ebs=$((ebs_rate * disk_gb))
total=$((ec2 + ebs))
printf 'EC2:   $%d.%02d\n' $((ec2 / 10000)) $((ec2 % 10000 / 100))
printf 'EBS:   $%d.%02d\n' $((ebs / 10000)) $((ebs % 10000 / 100))
printf 'total: $%d.%02d/month\n' $((total / 10000)) $((total % 10000 / 100))

Output

EC2:   $7.59
EBS:   $0.64
total: $8.23/month

Reading the two meters together

  • gp3 is EBS's current general-purpose SSD class, and older volumes use gp2. The distinction matters on real invoices, since gp3 is both faster and cheaper for most workloads.
  • 8 GB × $0.08 = $0.64, and $7.59 + $0.64 = $8.23. A real server's disk is never free.
  • The EBS charge is a storage meter, not a compute meter, so it keeps billing when the instance is stopped. Stopping an instance saves the $7.59 and not the $0.64, which surprises people who expected a stopped machine to cost nothing.

Which meter dominates a photo-sharing bill

Data transfer out dominates: 2,000 GB × $0.09 works out to roughly $180, about 80 times the storage cost.

This is meter 4 again. Storing bytes is cheap at $2.30 for 100 GB, and shipping them to the internet is not.

The asymmetry is easy to miss because it is invisible in the architecture. Nothing in the design says "bandwidth", and the S3 console shows a reassuringly small storage number while the transfer line quietly grows with every visitor.

It is also the business case for CDNs. A content delivery network serves repeat content from cheaper edge caches, so the same 2 TB costs meaningfully less and arrives faster, which is what lesson 9-1 builds.