Sub topic 7
Rightsizing over-provisioned resources
This chapter assumes you can run AWS CLI commands, read JSON output, and know the basic EC2 instance families (general purpose, compute optimized, memory optimized). It also assumes you have read the previous chapter on idle resources. Idle resources are things you can delete. Rightsizing covers resources that are in use but larger than the workload needs.
What rightsizing is
Rightsizing means matching a resource's capacity to what the workload actually consumes, with a safety margin. An m5.2xlarge instance (8 vCPU, 32 GiB) running at 6 percent CPU and 20 percent memory costs four times what an m5.large would. Both give the same result for that workload.
Over-provisioning happens for ordinary reasons:
- Teams size for a launch-day peak that never repeated.
- Engineers pick a large instance "to be safe" because resizing later feels risky.
- A workload changed (a feature was removed, a cache was added) and nobody revisited the instance.
- Copied infrastructure templates carry the original sizing forward.
Rightsizing applies to more than EC2. The same logic covers RDS instance classes, provisioned IOPS on EBS volumes, ElastiCache nodes, container CPU and memory reservations, and Lambda memory settings.
Order of operations
Rightsize before you buy commitments. A Savings Plan or Reserved Instance covers a fixed amount of spend. If you commit to a size you later shrink, you pay for capacity you no longer use. The dependency graph for this tutorial reflects this: rightsizing feeds into commitment discounts.
Step 1: Measure the right things
Utilization data must cover a full business cycle. Two weeks is a minimum. If the workload has monthly batch jobs or quarter-end spikes, look at a longer window, or you will shrink an instance right before its busiest day.
Look at these signals together:
| Signal | Where it comes from | Why it matters |
|---|---|---|
| CPU utilization (average and maximum) | CloudWatch, `AWS/EC2` namespace | Shows compute headroom |
| Memory utilization | CloudWatch agent only | EC2 does not publish memory by default |
| Network throughput | CloudWatch `NetworkIn` and `NetworkOut` | Smaller instances have lower bandwidth limits |
| Disk IOPS and throughput | CloudWatch EBS metrics | Instance types cap EBS bandwidth |
Averages hide spikes, so always pull the maximum as well. The following command returns daily average and maximum CPU for 14 days. Replace the instance ID with your own.
aws cloudwatch get-metric-statistics \
--namespace AWS/EC2 \
--metric-name CPUUtilization \
--dimensions Name=InstanceId,Value=i-0123456789abcdef0 \
--start-time 2026-11-12T00:00:00Z \
--end-time 2026-11-26T00:00:00Z \
--period 86400 \
--statistics Average Maximum \
--output tableA period of 86400 seconds gives one data point per day. A daily maximum is itself an average of one-minute or five-minute samples, so a spike shorter than the sampling interval can still be flattened. For latency-sensitive services, use a shorter period on the busiest days.
The memory blind spot
By default, EC2 reports CPU, network, and disk, but not memory. An instance that looks idle on CPU can be memory-bound. If you shrink it based on CPU alone, it may start swapping or hit the out-of-memory killer. Install the CloudWatch agent to publish memory (mem_used_percent) before you decide anything about memory-heavy workloads such as databases, JVM services, and caches.
Step 2: Use automated recommendations
AWS Compute Optimizer analyzes CloudWatch metrics and suggests instance types. You must opt in once per account (or organization):
aws compute-optimizer update-enrollment-status --status ActiveAfter the service has collected data (it can take up to about 12 hours for first results, and it needs at least 30 hours of metrics for an instance), list findings:
aws compute-optimizer get-ec2-instance-recommendations \
--query 'instanceRecommendations[].{Arn:instanceArn,Finding:finding,Current:currentInstanceType,Suggested:recommendationOptions[0].instanceType}' \
--output tableThe finding field takes one of these values:
OVER_PROVISIONED: at least one resource (CPU, memory, network) could be smaller.UNDER_PROVISIONED: the instance is constrained and may hurt performance. Cost is not the concern here.OPTIMIZED: the size fits.
By default, Compute Optimizer looks back 14 days. Longer lookback (up to 93 days) is available as a paid enhanced metrics feature. Without the CloudWatch agent, memory is not considered, and recommendations will note that limited data was available. Treat the output as a candidate list, not an order to execute.
Step 3: Choose the new size
Picking a smaller size in the same family is the simplest move. A general rule of thumb is to target a peak utilization of about 60 to 70 percent on the busiest resource, which leaves room for growth and failover.
Consider these options:
- Go down one or two sizes in the same family.
m5.2xlargetom5.largehalves vCPU and memory per step. This is low risk and easy to reverse. - Change family to fit the bottleneck. A memory-heavy service with idle CPU may fit an
rfamily type with fewer vCPUs. A CPU-bound service with spare memory may fit actype. - Move to a newer generation. Newer instance generations commonly give better price-performance. Check the current prices for your region, because the difference varies.
- Consider Graviton (Arm) instances. They often cost less for equal performance, but your software and container images must support arm64. Test first.
- Switch to burstable types such as
t3ort4g. These suit workloads with low average CPU and occasional bursts. If CPU credits run out and unlimited mode is on, you pay surplus charges, so watchCPUCreditBalance.
Step 4: Apply the change safely
For EBS-backed EC2 instances, a resize requires a stop and start. The steps below change one instance. Use a canary or one node behind a load balancer first.
aws ec2 stop-instances --instance-ids i-0123456789abcdef0
aws ec2 wait instance-stopped --instance-ids i-0123456789abcdef0
aws ec2 modify-instance-attribute \
--instance-id i-0123456789abcdef0 \
--instance-type Value=m5.large
aws ec2 start-instances --instance-ids i-0123456789abcdef0
aws ec2 wait instance-running --instance-ids i-0123456789abcdef0Check these before you stop anything:
- Public IP address. An instance without an Elastic IP gets a new public IP after a stop and start.
- Instance store volumes. Data on instance store disks is lost when the instance stops.
- Architecture and drivers. Moving between Intel/AMD and Graviton needs a matching AMI. Moving to a newer generation can require the ENA and NVMe drivers.
- Capacity. The target type may be unavailable in your Availability Zone at that moment. Keep the old type as your rollback.
Rightsizing beyond EC2
- RDS. Check
CPUUtilization,FreeableMemory, andDatabaseConnections. Changing the instance class causes a brief outage unless you use Multi-AZ, where the failover is short. Schedule it in a maintenance window. - EBS. You can raise volume size and change type online, but you cannot shrink a volume in place. To reduce size, create a new smaller volume and copy the data. For gp3, IOPS and throughput are set separately from size, so you can lower provisioned IOPS without moving data.
- Containers. Compare each task's CPU and memory reservations to observed use. Reservations that are too high waste cluster capacity, and reservations that are too low risk throttling or OOM kills.
- Lambda. More memory also adds CPU, so a higher setting can finish faster and cost less. Test several memory values against a representative payload.
Common mistakes
- Using averages alone. Peaks decide whether a smaller instance copes.
- Ignoring memory and network. A smaller type has lower network and EBS bandwidth limits as well.
- Using a short window. Two quiet weeks do not predict a month-end job.
- Rightsizing after buying commitments. Do it first, then commit to the new baseline.
- Skipping rollback planning. Record the original type and configuration before every change.
- Treating savings as permanent. Workloads grow, so schedule a recurring review.
Estimating the payoff
Savings per instance are the hourly price difference multiplied by hours running. If an instance runs 730 hours a month and moving down one size saves a given hourly amount, multiply that by 730 and by the number of instances. Use the AWS Pricing Calculator or the price list for exact figures in your region. Compute Optimizer also shows estimated monthly savings for each recommendation option.
Exercise
An instance averages 8 percent CPU over 14 days, with a daily maximum of 85 percent on two days. Compute Optimizer marks it OVER_PROVISIONED, but you have no memory data. Should you resize it now? What do you do first?
Show answer
Not yet. The 85 percent peaks show the CPU is used at times, so an average-based decision would be wrong, and the missing memory data means the recommendation ignores a possible memory bottleneck. First install the CloudWatch agent to collect memory, look at the peaks to see how long they last and whether they recur (for example a nightly job), and extend the window to cover a full business cycle. If peaks and memory still fit a smaller type with margin, resize one canary instance, monitor, then continue.
Exercise
Why should you finish rightsizing before purchasing a Savings Plan or Reserved Instance?
Show answer
A commitment fixes a spend level or instance size for one or three years. If you buy it for the current oversized fleet and then shrink the instances, the commitment covers capacity you no longer use, so you pay for it anyway and lose part of the savings. Rightsizing first lets you commit to the real baseline.