TExcelTAD
Home › AWS Cloud › Pricing and Cost Management

Pricing and Cost Management

AWS pricing follows three principles: pay as you go, pay less when you commit (Savings Plans, Reserved Instances), and pay less per unit as you use more (tiered pricing, e.g. for S3 storage and data transfer). The three main cost drivers are compute, storage and data transfer out.

Note: All prices in this lesson are example prices to make the arithmetic concrete. Real prices depend on Region and change over time, so check the AWS pricing pages and the AWS Pricing Calculator.

Cost tools

Tool What it does
AWS Pricing Calculator Estimate the cost of an architecture before you build it
AWS Free Tier Free usage for new accounts or small workloads (some always free, some for 12 months or as credits)
Billing dashboard / Bills What you are being charged, by service
AWS Cost Explorer Graphs and filters over past costs, forecasts, rightsizing and Savings Plans recommendations
AWS Budgets Alerts (and actions) when actual or forecast spend/usage passes a threshold
Cost and Usage Report / Data Exports The most detailed line-item data, delivered to S3 for analysis
Cost allocation tags Split costs by project, team or environment
AWS Cost Anomaly Detection Machine learning alerts for unusual spend
AWS Organizations consolidated billing One bill for many accounts, combined volume discounts

Creating a budget

bash
aws budgets create-budget --account-id 123456789012 \
    --budget '{"BudgetName":"monthly-50","BudgetLimit":{"Amount":"50","Unit":"USD"},"TimeUnit":"MONTHLY","BudgetType":"COST"}' \
    --notifications-with-subscribers '[{"Notification":{"NotificationType":"FORECASTED","ComparisonOperator":"GREATER_THAN","Threshold":80,"ThresholdType":"PERCENTAGE"},"Subscribers":[{"SubscriptionType":"EMAIL","Address":"ada@example.com"}]}]'

Model: a budget with forecast alerts

AWS Budgets can alert on actual spend and on forecast spend for the period. A simple linear forecast: spend so far ÷ days elapsed × days in the month.

python · try it yourself
BUDGET = 50.0
DAYS = 30
daily_spend = [1.2, 1.1, 1.3, 1.2, 1.4, 1.3, 2.9, 3.1, 3.0, 3.2]   # a forgotten instance from day 7

alerts_sent = set()
total = 0.0
for day, spend in enumerate(daily_spend, start=1):
    total += spend
    forecast = total / day * DAYS
    for kind, value, threshold in [("FORECASTED", forecast, 0.8), ("FORECASTED", forecast, 1.0), ("ACTUAL", total, 0.5)]:
        key = (kind, threshold)
        if value > BUDGET * threshold and key not in alerts_sent:
            alerts_sent.add(key)
            print(f"day {day:>2}: ALERT {kind} ${value:.2f} > {threshold:.0%} of ${BUDGET:.0f}")
    print(f"day {day:>2}: spent ${total:6.2f}, forecast ${forecast:6.2f}")
day  1: spent $  1.20, forecast $ 36.00
day  2: spent $  2.30, forecast $ 34.50
day  3: spent $  3.60, forecast $ 36.00
day  4: spent $  4.80, forecast $ 36.00
day  5: spent $  6.20, forecast $ 37.20
day  6: spent $  7.50, forecast $ 37.50
day  7: ALERT FORECASTED $44.57 > 80% of $50
day  7: spent $ 10.40, forecast $ 44.57
day  8: ALERT FORECASTED $50.62 > 100% of $50
day  8: spent $ 13.50, forecast $ 50.62
day  9: spent $ 16.50, forecast $ 55.00
day 10: spent $ 19.70, forecast $ 59.10

The 80% forecast alert fires on day 7 and the 100% forecast alert on day 8, long before actual spend gets anywhere near the budget. Catching a forgotten resource early is the main value of budgets.

Model: data transfer

Data transfer into AWS is generally free; transfer out to the internet is charged per GB, in tiers; transfer between AZs and Regions costs too. This model applies tiered pricing:

python · try it yourself
# example tiers for data transfer out to the internet, $/GB
TIERS = [(100, 0.0), (10_240, 0.09), (40_960, 0.085), (float("inf"), 0.07)]  # first 100 GB free (example)

def egress_cost(gb):
    cost, previous_limit = 0.0, 0
    for limit, price in TIERS:
        in_tier = max(0, min(gb, limit) - previous_limit)
        cost += in_tier * price
        previous_limit = limit
        if gb <= limit:
            break
    return cost

for gb in (50, 1_000, 20_000, 60_000):
    print(f"{gb:>7,} GB out: ${egress_cost(gb):10,.2f}  (${egress_cost(gb) / gb:.4f}/GB average)")
     50 GB out: $      0.00  ($0.0000/GB average)
  1,000 GB out: $     81.00  ($0.0810/GB average)
 20,000 GB out: $  1,742.20  ($0.0871/GB average)
 60,000 GB out: $  4,856.60  ($0.0809/GB average)

Ways to reduce it: serve content through CloudFront (cheaper egress, plus caching), keep chatty services in the same AZ, and use VPC endpoints for AWS service traffic.

Model: tagging and cost allocation

Untagged resources make it impossible to tell who is spending what. Cost Explorer can group by a cost allocation tag once it is activated:

python · try it yourself
from collections import defaultdict

line_items = [
    ("ec2", 310.0, {"project": "shop", "env": "prod"}),
    ("rds", 190.0, {"project": "shop", "env": "prod"}),
    ("ec2", 85.0,  {"project": "shop", "env": "dev"}),
    ("lambda", 12.5, {"project": "reports", "env": "prod"}),
    ("s3", 40.0,   {"project": "reports"}),
    ("ec2", 140.0, {}),                       # untagged!
]

by_project = defaultdict(float)
for service, cost, tags in line_items:
    by_project[tags.get("project", "(untagged)")] += cost

total = sum(by_project.values())
for project, cost in sorted(by_project.items(), key=lambda kv: -kv[1]):
    print(f"{project:<11} ${cost:8.2f}  {cost / total:5.1%}")
print(f"{'total':<11} ${total:8.2f}")
shop        $  585.00  75.2%
(untagged)  $  140.00  18.0%
reports     $   52.50   6.8%
total       $  777.50

Use tag policies (AWS Organizations) and AWS Config rules to enforce tagging, so the "untagged" bucket stays small.

Cost optimisation checklist

  1. Delete what you don't use: idle instances, unattached EBS volumes, old snapshots, unused Elastic IPs, forgotten NAT gateways and load balancers.
  2. Right-size: match instance types to measured usage (Compute Optimizer).
  3. Schedule non-production resources to stop at night and weekends.
  4. Buy Savings Plans for the steady baseline; use Spot for interruptible work.
  5. Pick the right storage class and lifecycle rules.
  6. Prefer managed and serverless services where they reduce total cost (including people's time).

Test yourself

Which tool should you set up first to be warned when spending is heading over a limit?

  1. AWS Budgets
  2. AWS Artifact
  3. Amazon Inspector
  4. AWS Config

Which tool estimates the cost of an architecture BEFORE you deploy it?

  1. Cost Explorer
  2. AWS Pricing Calculator
  3. Cost and Usage Report
  4. Billing dashboard

Which kind of data transfer is generally free?

  1. Out to the internet
  2. Between Regions
  3. Into AWS from the internet
  4. Between AZs