The Amazon EC2 r-family latest generation policy flags memory-optimized EC2 instances running an older r-family generation, such as r3 or r4, and recommends a current generation such as r5, r6i, or r7g. An r5.large costs about 24% less per month than an r3.large and about 5% less than an r4.large in US East (N. Virginia), while adding memory and a newer processor. Apply this policy to any aws_instance or aws_launch_template whose instance_type starts with r3. or r4..
Attribute | Detail |
|---|---|
Cloud Provider | Amazon Web Services (AWS) |
Resource Type | Amazon EC2 memory-optimized instances, r-family |
Terraform Attribute |
|
Non-compliant Values | Previous r-family generations, for example |
Compliant Value | A current generation such as |
Cost Impact | About 24% lower on-demand cost moving r3 to r5, about 5% moving r4 to r5, with 16 GiB instead of 15.25 GiB of memory |
Why This Policy Matters
How It Helps Reduce Cloud Costs
Amazon EC2 r-family instances are memory-optimized. Teams use them for in-memory caches, relational databases, and analytics jobs that need a high ratio of RAM to vCPU.
AWS releases a new r-family generation every few years. From r3 through r6i, each generation costs the same or less per hour than the one before it, on faster hardware.
An r3.large runs on an Intel Xeon E5-2670 v2 processor from 2013. An r5.large runs on an Intel Xeon Platinum 8175 processor, is EBS-optimized by default, and supports enhanced networking through the Elastic Network Adapter (ENA).
Staying on r3 or r4 means paying more for older hardware. This is a common source of wasted spend in long-lived AWS accounts, where the instance type was chosen years ago and never revisited.
Potential Savings
The Amazon EC2 r-family generation upgrade saves money because the current generation costs less per hour than the generation it replaces.
Instance type | vCPUs | Memory | Approx. monthly on-demand cost (US East, Linux) |
|---|---|---|---|
| 2 | 15.25 GiB | $121 |
| 2 | 15.25 GiB | $97 |
| 2 | 16 GiB | $92 |
| 2 | 16 GiB | $92 |
| 2 | 16 GiB | $78 |
Monthly figures assume 730 hours at US East (N. Virginia) on-demand Linux rates. Prices vary by region, operating system, and purchase option.
Moving one r3.large to r5.large saves about $29 per month, or roughly $350 per year. The same ratio applies across sizes, so a fleet of r3.2xlarge or r3.4xlarge instances saves proportionally more.
The r4 to r5 saving is smaller, about 5%. The case for that move rests as much on the newer processor, higher EBS bandwidth, and extra memory as on price.
Implementation Guide
Infrastructure-as-Code Example (Terraform)
The following examples show an Amazon EC2 instance on a previous r-family generation, and the corrected configuration on r5.
Non-compliant configuration: EC2 instance on r4
This configuration pays more every hour for an older Broadwell processor and less memory than a current-generation instance of the same size.
Compliant configuration: EC2 instance on r5
The only change is the instance_type value. The resource name stays the same, so Terraform updates the existing instance instead of creating a new one.
The same fix applies to launch templates used by Auto Scaling groups:
Step-by-Step Fix Instructions
Search Terraform code for
instance_typevalues that start withr3.orr4.inaws_instanceandaws_launch_templateresources.Check shared modules,
.tfvarsfiles, and variable defaults. Older instance types often sit in avariable "instance_type"default rather than the resource block.Confirm the AMI supports the AWS Nitro System. r5 and later need ENA and NVMe drivers, which current Amazon Linux, Ubuntu, and Windows Server AMIs include.
For r3 instances, check whether the workload writes to the local instance store SSD. r5 and r6i have no instance store, so use r5d or r6id if the workload needs local disk.
Pick the target size by matching vCPU count. Consider r7g only if the workload and AMI run on Arm64.
Change the
instance_typevalue and runterraform plan. Confirm the plan shows an in-place update toinstance_type, not a resource replacement.Apply during a maintenance window. Changing the instance type on an
aws_instancestops and starts the instance.Validate the workload, then add Infracost to CI/CD so new r3 or r4 instance types are flagged in pull requests before they merge.
Best Practices
Pin approved instance types in shared Terraform modules with a
validationblock, so previous-generation r-family types fail atterraform plan.Migrate development and staging instances first. A stop and start can surface driver or boot issues on old AMIs.
Review Reserved Instances and Savings Plans before migrating. A standard Reserved Instance for r4 does not cover r5 usage; Compute Savings Plans do apply across families.
Default Intel workloads to r6i, which matches r5 on price with a newer Ice Lake processor. r7i costs about 5% more per hour than r6i in US East.
Use r7g only when the software stack already supports Arm64.
This policy targets x86 upgrades within the r-family. Moving to Graviton is a separate decision with its own testing cost.
Tools and Scripts
How does Infracost detect previous-generation Amazon EC2 r-family instances automatically?
The Amazon EC2 r-family latest generation policy is available in Infracost, including in the free trial. When Infracost runs in CI/CD, it checks EC2 resources in each pull request and flags previous-generation r-family instance types in the PR comment, with the file and line to change.
The same Infracost pull request comment shows the estimated monthly cost of the change. Reviewers see what an r4.large costs before it merges, not on next month's AWS bill.
Infracost also scans connected repositories for r3 and r4 instance types already in code. FinOps and platform teams can burn down that backlog over time, tracking issues prevented in pull requests separately from existing issues fixed.
Teams can set the policy to warn engineers or block pull requests, and can limit it to new resources only so an unrelated PR does not force a risky change.
To find previous-generation r-family types in a Terraform codebase:
To list running EC2 instances on r3 or r4 with the AWS CLI:
If an instance is managed by Terraform, change instance_type in code rather than in the console. Otherwise the next terraform apply sets the old type again.
Examples of Impact
Savings from the Amazon EC2 r-family generation upgrade scale with instance size and fleet count, because the code change per resource is one attribute.
Illustrative example: a self-managed cache tier. A platform team runs eight r3.2xlarge instances for an in-memory cache. Moving to r5.2xlarge cuts on-demand compute cost by about 24% and adds memory per node, after confirming the cache does not rely on the r3 instance store.
Illustrative example: an Auto Scaling worker pool. A data team runs batch workers from a launch template set to r4.xlarge. Updating the launch template to r5.xlarge and rolling the group through an instance refresh saves about 5% per hour and raises EBS throughput for the same job.
(These are illustrative scenarios, not specific customer accounts.)
Considerations and Caveats
The Amazon EC2 r-family upgrade is low risk for most workloads, but old AMIs and instance store usage are where migrations go wrong.
Nitro driver support. r5 and later require ENA and NVMe drivers. Very old custom AMIs may not boot until these drivers are installed.
Instance store loss. r3 includes a local SSD. r5 and r6i have none, and instance store data does not survive a stop.
Restart required. Changing
instance_typestops and starts the instance. Without an Elastic IP, the public IPv4 address changes.Reservations do not move automatically. Convertible Reserved Instances for r3 or r4 can be exchanged for r5. Standard Reserved Instances must run out or be sold on the Reserved Instance Marketplace.
Provider-specific. This policy targets Amazon EC2 through the
awsTerraform provider. Azure and Google Cloud have their own memory-optimized generations with different names.
Related Policies and Concepts
Amazon EC2 - consider using latest generation instances for m family instances: the same generation upgrade for general-purpose EC2 instances.
Amazon EC2 - consider using latest generation instances for c family instances: the compute-optimized equivalent of this r-family policy.
Amazon RDS - consider using latest generation instances for r family instances: the same memory-optimized upgrade applied to
aws_db_instanceclasses such asdb.r4.Amazon ElastiCache - consider using latest generation nodes for r family nodes: the managed-cache version of this policy for
cache.rnode types.AWS EC2 - consider using Graviton instances: a related Compute-group policy for moving x86 instances, including r-family, to Arm-based Graviton types such as r7g.
Frequently Asked Questions (FAQs)
Is this policy supported in Infracost?
Yes. The Amazon EC2 r-family latest generation policy is supported in Infracost and available in the free trial. Infracost flags EC2 resources using r3 or r4 instance types in pull requests, so the team can change the instance type before merge.
Can this policy be customized?
Yes. Teams can configure how Infracost enforces the Amazon EC2 r-family latest generation policy. For example, a finding can warn engineers or block the pull request, and can apply to new resources only.
Does Infracost automatically fix violations?
No. Infracost reports each previous-generation Amazon EC2 r-family instance type in the pull request with the file and line to change. Choosing between r5, r5d, r6i, or r7g depends on instance store and architecture needs, so the team makes that decision.
Is this policy cloud-agnostic?
No. The Amazon EC2 r-family latest generation policy targets Amazon EC2 through the aws Terraform provider. Azure and Google Cloud have their own memory-optimized VM generations, with different resource and attribute names.
Which Amazon EC2 r-family generation should replace r3 or r4?
For most x86 workloads, r5 or r6i is the direct replacement, at the same hourly rate in US East. Choose r5d or r6id when the workload needs local instance storage. Choose r7g when the Amazon EC2 workload already runs on Arm64.
Does upgrading an Amazon EC2 r-family instance cause downtime?
Yes, briefly. Changing the instance type on an Amazon EC2 instance requires a stop and start. Plan the change in a maintenance window, or roll it through an Auto Scaling group with an instance refresh.
How often should I review Amazon EC2 instance generations?
Teams running Infracost in CI/CD get an Amazon EC2 r-family check on every pull request that touches an EC2 resource. For existing instances, a quarterly review of instance generations is a reasonable cadence for most teams.
Create Free Account
This policy is supported in Infracost and available in the free trial. Sign up today and scan your code using our entire library of FinOps policies.