Sub topic 14
Measuring unit costs
Total spend tells you how much you paid. It does not tell you whether you paid a reasonable amount for what you got. This chapter covers how to turn cost data into unit costs, such as cost per order or cost per active user, and how to avoid the common mistakes in doing so.
It assumes you have read the earlier chapters on tagging and cost allocation, budgets, and commitment discounts. You should be comfortable running AWS CLI commands and reading short Python.
Why total spend misleads
A monthly bill that rises 20% could mean waste or success. If traffic doubled, a 20% increase means efficiency improved. If traffic was flat, something is wrong. Totals cannot separate these cases. A unit cost can, because it divides spend by the amount of business value produced.
Unit costs help with three decisions:
- Judging a change. After a rightsizing project or an architecture change, did cost per unit fall?
- Forecasting. If the business expects 30% more orders, a known cost per order gives a first estimate of the spend.
- Pricing and margin. Product teams can compare cost to serve a customer against the revenue that customer brings.
Choosing the unit
A good unit metric has three properties. It is tied to value the customer or business sees. It is measured reliably by a system you trust. It moves roughly in step with variable cost.
| Workload | Candidate unit | Source of the denominator |
|---|---|---|
| E-commerce checkout | Cost per completed order | Orders database |
| API platform | Cost per million requests | Load balancer or gateway metrics |
| Video service | Cost per streamed hour | Playback logs |
| Data pipeline | Cost per GB processed | Pipeline job metrics |
| SaaS product | Cost per active customer | Billing or identity system |
Prefer a metric the business already reports. If finance and engineering both use "completed orders," nobody argues about the denominator. Avoid raw technical counts such as CPU hours as the unit. They measure input, not output, so they cannot show whether you got more efficient.
Building the numerator
The numerator is the cost attributable to the product. Three problems come up.
Direct costs
Direct costs are resources used by one product only. If tagging is in place, filter by the cost allocation tag, for example product=checkout. The tag must be activated as a cost allocation tag in the Billing console. It only applies to usage from the activation date onward, so earlier months will show no tag data.
Shared costs
Some costs serve many products: a shared Kubernetes cluster, a NAT gateway, a logging account, support plans. You have to choose an allocation rule and apply it consistently. Common rules are:
- Proportional to the product's direct spend.
- Proportional to a usage measure, such as CPU requests or log volume.
- An even split, which is simple but rarely fair.
Pick one rule per shared cost and write it down. Changing rules between months makes trends meaningless.
Untagged costs
Untagged spend belongs to nobody, so it is left out of every unit cost, and the unit costs come out too low. Track untagged spend as a percentage of the total. If it is large, fix tagging before trusting any unit metric.
Which cost type to use
Use amortized cost, not unblended cost, for unit economics. Unblended cost shows a Savings Plan or Reserved Instance upfront payment in the month you paid it. Amortized cost spreads that payment across the term. With unblended cost, a product's unit cost jumps in a month when a commitment is purchased, and the jump has nothing to do with efficiency.
Also decide how to treat credits and refunds. Include them in a "net" view for finance. Exclude them in an engineering view, so credits do not hide real cost growth.
Building the denominator
The denominator comes from a business or application system, not from AWS. Pull it for exactly the same period as the cost. Check these points:
- Same time window. A cost month of October 1 to October 31 needs orders from the same dates and the same time zone. Cost Explorer uses UTC.
- Same scope. If the cost covers three regions, the count must include all three.
- Meaningful units. Count completed orders, not attempted ones, if failed attempts are not the value you deliver.
A worked example
The script below reads a tagged product's monthly amortized cost from the Cost Explorer API and divides it by an order count you supply.
import sys
import boto3
def monthly_cost(product, start, end):
ce = boto3.client("ce", region_name="us-east-1")
response = ce.get_cost_and_usage(
TimePeriod={"Start": start, "End": end},
Granularity="MONTHLY",
Metrics=["AmortizedCost"],
Filter={"Tags": {"Key": "product", "Values": [product]}},
)
return sum(
float(period["Total"]["AmortizedCost"]["Amount"])
for period in response["ResultsByTime"]
)
if __name__ == "__main__":
product, start, end, orders = sys.argv[1], sys.argv[2], sys.argv[3], int(sys.argv[4])
cost = monthly_cost(product, start, end)
print(f"{product}: ${cost:,.2f} total, ${cost / orders:.4f} per order")Run it with the product tag value, the start date, the exclusive end date, and the order count:
python unit_cost.py checkout 2026-10-01 2026-11-01 690000The End date in Cost Explorer is exclusive, so 2026-11-01 covers all of October. The caller needs the ce:GetCostAndUsage permission. Each Cost Explorer API request is charged, so run this on a schedule such as daily or monthly, not on every dashboard refresh.
For direct costs only, this script is enough. To add allocated shared costs, compute each product's share and add it to the result before dividing.
Reading the trend
Here is a three-month history for the checkout product.
| Month | Cost (USD) | Orders | Cost per order |
|---|---|---|---|
| August | 8,400 | 600,000 | 0.0140 |
| September | 9,100 | 700,000 | 0.0130 |
| October | 11,000 | 690,000 | 0.0159 |
Between August and September, spend rose but unit cost fell, which is healthy scaling. In October, orders were nearly flat while spend rose by about 21%, and unit cost jumped by about 22%. That is the signal to investigate. Look at the service breakdown for October, check for new resources, and compare against any deploys or traffic changes.
Unit cost usually has a fixed component, such as baseline databases and minimum capacity, and a variable component. When volume is low, the fixed part spreads over fewer units, and cost per unit looks high. Comparing a quiet month with a busy month without that in mind leads to wrong conclusions. If your volume varies a lot, track the variable part separately.
Putting unit costs into a review process
The flow below shows where unit cost fits.
In the review, set a target unit cost for each product and give an owner a clear question: is the number within target, and if not, why? Targets work better as a range or a trend, such as "no more than 5% above last quarter," than as a single value, because unit costs move naturally with volume and mix.
Common mistakes
- Mixing periods. Cost is month-to-date and the order count is a full month. Always compare complete periods, and remember that recent Cost Explorer data can lag by up to a day.
- Using unblended cost with commitments. This creates artificial spikes, as described above.
- Moving the denominator. Redefining "order" mid-year breaks the history. If you must change it, recompute the old months.
- Ignoring shared-cost rules. Silent changes to allocation make one team's unit cost drop and another's rise with no real change.
- Chasing the number. Cutting cost per unit by hurting reliability or performance is not an improvement. Pair the unit cost with a quality measure such as error rate or latency.
Exercise
Last month a product cost 12,000 USD and served 400,000 orders. This month it cost 13,500 USD and served 500,000 orders. Did total spend and cost per order move in the same direction? Give the numbers.
Show answer
No. Total spend rose 12.5% (13,500 / 12,000). Cost per order fell from 0.030 USD (12,000 / 400,000) to 0.027 USD (13,500 / 500,000), a drop of 10%. Spend grew, but each order became cheaper to serve.
Exercise
A team buys a one-year Savings Plan with an upfront payment in November. Their November unit cost doubles when computed from unblended cost. What should they change, and why?
Show answer
Switch the numerator to amortized cost. Amortized cost spreads the upfront payment over the term, so the November spike disappears and unit cost reflects the real, steady cost of serving each unit.