Sub topic 7
Cost Optimization: delivering value at the lowest price point
This chapter assumes you know core AWS services (EC2, S3, EBS, IAM, VPC), can read an AWS bill at a basic level, and have read the framework overview. Cost Optimization is the pillar that asks whether you are paying only for what delivers business value. The goal is not the lowest bill. The goal is the lowest price for the outcome you need, at the quality and risk level you have chosen.
What the pillar asks for
The Well-Architected Framework describes Cost Optimization as the ability to run systems that deliver business value at the lowest price point. It organizes the work into five design principles:
- Implement cloud financial management. Treat cost control as a skill with owners, training, and routines, not a task finance does once a quarter.
- Adopt a consumption model. Pay for what you use. Stop non-production resources when nobody is using them.
- Measure overall efficiency. Compare the business output (orders processed, users served) to the cost of producing it.
- Stop spending money on undifferentiated heavy lifting. Use managed services where running the same thing yourself adds cost but no advantage.
- Analyze and attribute expenditure. Know which team, product, or environment causes each cost, so owners can see and act on it.
The pillar groups its best practices into five areas: cloud financial management, expenditure and usage awareness, cost-effective resources, demand management, and optimizing over time. The sections below follow that order.
Cloud financial management
Cost problems are usually organizational before they are technical. Nobody owns the bill, so nobody reduces it. Practices in this area include:
- Naming a person or small team that is responsible for cost, often called a FinOps function.
- Setting budgets and reviewing them on a fixed schedule.
- Giving engineers visibility into the cost of what they build.
- Adding cost as a factor in design reviews, next to security and reliability.
Expenditure and usage awareness
You cannot reduce spending you cannot attribute. This area covers accounts, tags, reports, and alerts.
Account structure
Separate AWS accounts under AWS Organizations give you a hard boundary for billing and permissions. A common layout has separate accounts for production, development, and shared tooling. Consolidated billing combines usage across accounts, so volume discounts and commitment discounts apply to the whole organization.
Cost allocation tags
A tag is a key-value label on a resource. After you activate a tag as a cost allocation tag in the Billing console, it appears in cost reports. Without tags, a bill says you spent money on EC2. With tags, it says the orders-api service in production owned by team-checkout spent it.
aws ec2 create-tags \
--resources i-0123456789abcdef0 \
--tags Key=Application,Value=orders-api Key=Environment,Value=production Key=Owner,Value=team-checkoutTags only help if they are applied consistently. Enforce a required set with tag policies in AWS Organizations or with checks in your deployment pipeline.
Visibility tools
| Tool | What it does |
|---|---|
| AWS Cost Explorer | Charts and filters past cost and usage, and gives forecasts. |
| AWS Budgets | Sets a threshold for cost or usage and sends an alert or triggers an action when you cross it. |
| AWS Cost and Usage Report | Delivers the most detailed billing data to S3 for analysis with tools such as Athena. |
| AWS Cost Anomaly Detection | Flags unexpected spending changes using machine learning. |
A budget with an alert is a cheap safeguard. The following command creates a monthly cost budget. Replace the account ID and email address with your own.
aws budgets create-budget \
--account-id 111122223333 \
--budget '{
"BudgetName": "orders-api-monthly",
"BudgetLimit": {"Amount": "500", "Unit": "USD"},
"TimeUnit": "MONTHLY",
"BudgetType": "COST"
}' \
--notifications-with-subscribers '[
{
"Notification": {
"NotificationType": "ACTUAL",
"ComparisonOperator": "GREATER_THAN",
"Threshold": 80,
"ThresholdType": "PERCENTAGE"
},
"Subscribers": [
{"SubscriptionType": "EMAIL", "Address": "[email protected]"}
]
}
]'This sends an email when actual spending passes 80 percent of the 500 USD limit.
Cost-effective resources
This area is where most of the technical savings come from. It has four parts: choose the right service, choose the right size, choose the right pricing model, and plan data transfer.
Select the right service
Compare total cost of ownership, not just the unit price. A self-managed database on EC2 may have a lower hourly price than a managed one, but you also pay for patching, backups, failover design, and the engineers who do that work. A serverless function can be far cheaper than an always-on server for spiky traffic, and more expensive for steady high traffic. Run the numbers for your own load.
Right-size resources
Right-sizing means matching the resource to the measured need. Look at CPU, memory, network, and storage metrics over a representative period, including peaks, before you change anything. AWS Compute Optimizer analyzes this data and recommends instance types and sizes. Memory metrics need the CloudWatch agent, so without it the recommendations rest on CPU and network alone.
Also look for idle and orphaned resources: unattached EBS volumes, old snapshots, unused Elastic IP addresses, idle load balancers, and forgotten test environments.
aws ec2 describe-volumes \
--filters Name=status,Values=available \
--query 'Volumes[].{Id:VolumeId,SizeGiB:Size,Created:CreateTime}' \
--output tableThis lists EBS volumes that are not attached to any instance. Each one is billed until you delete it. Snapshot first if the data might matter.
Choose the pricing model
AWS offers several ways to pay for compute. The right mix depends on how predictable and how interruptible the work is.
| Model | Best for | Trade-off |
|---|---|---|
| On-Demand | New, unpredictable, or short-lived workloads | Highest unit price, no commitment |
| Savings Plans | Steady usage you can commit to for one or three years | Commitment in dollars per hour. Unused commitment is still billed. |
| Reserved Instances | Steady usage of specific instance configurations | Less flexible than Savings Plans for most workloads |
| Spot Instances | Fault-tolerant, flexible work such as batch jobs, CI, and stateless workers | AWS can reclaim capacity with a two-minute warning |
A practical approach is to cover your steady baseline with commitments, serve variable demand with On-Demand or Auto Scaling, and run interruptible work on Spot. Commit only to usage you have measured. A commitment sized from a forecast that turns out wrong is a cost, not a saving.
Plan for data transfer
Data transfer charges surprise many teams. Traffic into AWS is generally free. Traffic out to the internet, between Regions, and often between Availability Zones is billed. Design choices that reduce it include:
- Keeping chatty components in the same Availability Zone when reliability requirements allow it.
- Using Amazon CloudFront to serve content from edge locations.
- Using VPC gateway endpoints for S3 and DynamoDB, which carry no hourly or data processing charge, instead of sending that traffic through a NAT gateway.
The last item is a common win. NAT gateways charge per GB processed, so large S3 transfers from private subnets through NAT can cost real money for no benefit.
Demand management
Supply should follow demand. Two techniques do most of the work:
- Auto Scaling adds and removes capacity as load changes, so you do not hold peak capacity all day.
- Scheduling stops development and test environments outside working hours. An environment used 50 hours a week but running 168 hours is idle about 70 percent of the time.
Storage follows the same logic. S3 lifecycle rules move objects to cheaper storage classes as they age, and expire them when they are no longer needed.
{
"Rules": [
{
"ID": "age-out-logs",
"Status": "Enabled",
"Filter": { "Prefix": "logs/" },
"Transitions": [
{ "Days": 30, "StorageClass": "STANDARD_IA" },
{ "Days": 90, "StorageClass": "GLACIER" }
],
"Expiration": { "Days": 365 }
}
]
}Apply it with aws s3api put-bucket-lifecycle-configuration --bucket example-bucket --lifecycle-configuration file://lifecycle.json. Check minimum storage durations and per-object transition fees first. Small objects can cost more after a transition than before.
Optimizing over time
Prices, instance families, and services change. A decision that was right two years ago may not be right now. Schedule regular reviews of your architecture and spending. Newer instance generations, such as Graviton-based instances, often deliver better price-performance than older ones. Test your workload on them rather than assuming.
Common errors
- Optimizing the wrong thing. Cutting a 50 USD resource while a 5,000 USD data transfer line goes unexamined. Start with the largest cost lines in Cost Explorer.
- Over-committing. Buying a three-year commitment for usage that later moves to a different service or shrinks.
- Right-sizing from averages. An instance that averages 10 percent CPU may hit 90 percent every night during a batch run.
- Ignoring the trade-off. Dropping Multi-AZ, backups, or capacity headroom saves money and weakens the Reliability pillar. Record such choices as deliberate decisions, not accidents.
- Untagged spend. If 40 percent of the bill has no owner tag, nobody can be asked to reduce it.
How this appears in a review
In a Well-Architected review, Cost Optimization questions ask whether you have a cost owner, whether you can attribute costs to workloads, whether resources are sized from data, whether you use suitable pricing models, and whether you review regularly. Answers that show no process for any of these are typically flagged as medium or high risk. The AWS Well-Architected Tool lets you list them for this pillar:
aws wellarchitected list-answers \
--workload-id <workload-id> \
--lens-alias wellarchitected \
--pillar-id costOptimizationExercise
A team runs a steady production database and a nightly batch job that can safely restart if interrupted. Their development environment is used on weekdays from 9:00 to 18:00. Which pricing or demand technique fits each of the three, and why?
Show answer
Production database: a Savings Plan or Reserved Instance, because the usage is steady and predictable, so a commitment lowers the unit price. Nightly batch job: Spot Instances, because the work tolerates interruption and Spot gives the largest discount. Development environment: On-Demand with a schedule that stops it outside working hours, because it is idle most of the week and a commitment would pay for unused time.
Exercise
A private subnet downloads several terabytes a month from S3 through a NAT gateway. Name the charge that is growing and a change that removes it.
Show answer
The NAT gateway data processing charge (per GB) is growing. Adding a VPC gateway endpoint for S3 and routing S3 traffic through it removes that charge, because gateway endpoints have no hourly or data processing fee.