在打印窗口把「目标」选为「另存为 PDF」即可保存,页面已带 awsgood.com 版权水印。 返回原文

www.awsgood.com

EC2 按需实例与预留实例:差异核对

2026-11-06 AWS Config 约 7 分钟

先说结论

差异,按影响账单的顺序来看

按需定价是按运行秒数计费的费率。RI 定价是作用于匹配资源占用的合同,匹配每小时发生一次,与你的 Auto Scaling 组正在做什么无关。

这一句话解释了大多数坑。空闲的 RI 并不是“没帮你省钱”——你已经付过钱了。闲置未用的按需容量则完全不产生费用。

按需实例 标准 RI,1 年 可转换 RI,3 年
承诺 无 1 年 3 年
计费粒度 按秒 每小时匹配 每小时匹配
相对按需实例的典型折扣 0% 约 30–40% 约 50–60%
大小灵活性(Linux) 不适用 是,同一实例族 是,同一实例族
更改实例族 不适用 否(仅可等值交换) 是,可交换
转售 不适用 RI Marketplace(美国卖家) 否
覆盖 Spot / Fargate 不适用 否 否

折扣百分比因区域、操作系统和实例类型而异——请从 API 获取 FixedPrice,不要相信任何表格,包括这张表。

购买后要关注的两个数字是覆盖率(由 RI 覆盖的实例小时占比)和利用率(实际消耗的 RI 小时占比)。覆盖率 95%、利用率 60% 意味着你是为一个再也没回来的峰值买的。

预检:在承诺一年前先运行三条命令

首先,找出实际正在运行的内容,以及——关键的是——哪些不是按需实例。

aws ec2 describe-instances 
  --filters "Name=instance-state-name,Values=running" 
  --query 'Reservations[].Instances[].{Type:InstanceType,AZ:Placement.AvailabilityZone,Platform:PlatformDetails,Lifecycle:InstanceLifecycle}' 
  --output table


`Lifecycle` comes back empty for On-Demand and `spot` for Spot. RIs are invisible to Spot and Fargate usage, so if a third of your fleet is Spot, cut the number you were about to buy by a third before you do anything else.


按需实例的 `Lifecycle` 返回空值,Spot 实例返回 `spot`。RI 不会覆盖 Spot 和 Fargate 用量,所以如果你的机群中有三分之一是 Spot,在做任何其他事情之前,先把准备购买的数量削减三分之一。

接下来,查看 90 天内按类型划分的支出。Cost Explorer 数据大约滞后 24 小时,所以今天的购买没有显示出来时不要慌。

```bash
aws ce get-cost-and-usage 
  --time-period Start=2025-06-01,End=2025-09-01 
  --granularity MONTHLY 
  --metrics UnblendedCost UsageQuantity 
  --filter '{"Dimensions":{"Key":"INSTANCE_TYPE","Values":["m6i.large"]}}' 
  --output table


Then check existing coverage, because buying on top of an already-covered family is how you end up with a utilization report in the 50s.


然后检查现有覆盖率,因为在一个已经被覆盖的实例族上继续购买,正是最终得到 50% 多利用率报告的原因。

```bash
aws ce get-reservation-coverage 
  --time-period Start=2025-08-01,End=2025-09-01 
  --granularity MONTHLY 
  --group-by Type=DIMENSION,Key=INSTANCE_TYPE


Anything already above ~85% coverage doesn't need another RI.


任何覆盖率已经高于约 85% 的对象都不需要再买 RI。

## 购买:可直接复制粘贴的步骤

找到 offering ID。期限以秒为单位——一年是 `31536000`,三年是 `94608000`。

```bash
aws ec2 describe-reserved-instances-offerings 
  --instance-type m6i.large 
  --instance-tenancy default 
  --product-description "Linux/UNIX" 
  --offering-class standard 
  --offering-type "All Upfront" 
  --filters Name=scope,Values=Region 
  --duration 31536000 
  --query 'ReservedInstancesOfferings[].[ReservedInstancesOfferingId,Scope,AvailabilityZone,FixedPrice,UsagePrice]' 
  --output table


If you skip the `scope` filter you'll get both zonal and regional rows in the same output. Zonal offerings have an AZ populated and reserve capacity in that one AZ; regional offerings leave `AvailabilityZone` blank and follow instances anywhere in the region. Filter the wrong way and `ReservedInstancesOfferings` comes back as an empty `[]`, which reads like a broken command but is just a too-narrow filter.


如果跳过 `scope` 过滤器,你会在同一份输出中得到可用区级和区域级两种行。可用区级 offering 会填充 AZ,并在该可用区预留容量;区域级 offering 会让 `AvailabilityZone` 保持为空,并跟随区域内任意位置的实例。过滤方式不对时,`ReservedInstancesOfferings` 会返回空的 `[]`,看起来像命令坏了,其实只是过滤器太窄。

始终先进行 dry-run。下面这个错误就是成功的情况:

```bash
aws ec2 purchase-reserved-instances-offering 
  --reserved-instances-offering-id 5ec28df5-EXAMPLE-4c1a-9f0e-EXAMPLE 
  --instance-count 1 
  --dry-run


```text
An error occurred (DryRunOperation) when calling the PurchaseReservedInstancesOffering operation:
Request would have succeeded, but DryRun flag is set.


Drop `--dry-run` to buy. The response contains a `ReservationId` — store it somewhere; it is not the same identifier as `ReservedInstancesId` and you'll need both later.


去掉 `--dry-run` 即可购买。响应中包含 `ReservationId`——把它存到某处;它和 `ReservedInstancesId` 不是同一个标识符,之后两者都会用到。

## 每个重要参数,以及我会选的值

| 参数 | 控制什么 | 推荐值 |
|---|---|---|
| `--instance-type` | 哪个资源占用获得折扣 | 稳态小时占比 ≥70% 的实例族/大小 |
| `--offering-class` | `standard` 还是 `convertible` | 除非很可能迁移,否则选 `standard` |
| `--offering-type` | `No`/`Partial`/`All Upfront` | 如果现金流允许,选 `All Upfront` |
| `--duration` | 期限(秒) | 首次购买选 `31536000` |
| `--instance-count` | 购买多少个 RI | 稳态下限,而非峰值 |
| `--product-description` | 操作系统/平台字符串 | `Linux/UNIX`(也存在带 VPC 后缀的变体) |
| `--instance-tenancy` | 共享还是专用 | `default` |
| `--filters Name=scope` | 区域级还是可用区级 | `Region` |

`Partial Upfront` 在整个期限内总成本略高,但能保留现金流动性;`No Upfront` 成本最高,主要适用于承诺本身就是你要对冲的风险时。

## 24 小时后验证,数字不对时回退

检查预留实例是否存在,并趁还没忘记录下结束日期。

```bash
aws ec2 describe-reserved-instances 
  --filters Name=state,Values=active 
  --query 'ReservedInstances[].[ReservedInstancesId,InstanceType,Scope,AvailabilityZone,InstanceCount,Duration,End]' 
  --output table


Here's where we got burned. Six zonal `m5.xlarge` RIs were bought in `eu-west-1a`, because that's where the instances happened to be on the day of the purchase. Three weeks later an ASG rebalance moved most of the fleet to 1b and 1c. The bill didn't drop, and the coverage report sat at 41% — the zonal RIs simply had nothing to match.

The verification is one grouped call. `AVAILABILITY_ZONE` in the group-by is what exposed it:


我们就是在这里吃了亏。六个可用区级 `m5.xlarge` RI 被买在 `eu-west-1a`,因为购买当天实例恰好在那里。三周后,一次 ASG 再平衡把大部分机群迁移到了 1b 和 1c。账单没有下降,覆盖率报告停留在 41%——这些可用区级 RI 根本没有可匹配的对象。

验证只需一次分组调用。正是 group-by 中的 `AVAILABILITY_ZONE` 暴露了这个问题:

```bash
aws ce get-reservation-coverage 
  --time-period Start=2025-07-01,End=2025-07-22 
  --granularity DAILY 
  --group-by Type=DIMENSION,Key=INSTANCE_TYPE Type=DIMENSION,Key=AVAILABILITY_ZONE


Standard RIs can be modified on the spot — scope, AZ, count, network — with no fee and no new term. We flipped all six from zonal to regional, waited for the modification to report `fulfilled`, then re-ran the coverage query over the following week: 41% → 96%, and the on-demand line in Cost Explorer shrank by roughly the amount we'd forecast. `aws ec2 describe-reserved-instances-modifications` is where you confirm the state; it sits at `fulfilled`, not `completed`.

Where an RI genuinely can't be used, standard RIs can be listed on the RI Marketplace (US-based sellers) or exchanged for equal-or-greater value. Convertible RIs cannot be resold, only exchanged — that's the real cost of the flexibility.


标准 RI 可以当场修改——范围、AZ、数量、网络——不收费,也不会产生新期限。我们把六个全部从可用区级改为区域级,等待修改状态报告为 `fulfilled`,然后在接下来一周重新运行覆盖率查询:41% → 96%,Cost Explorer 中的按需费用行减少了大约我们预测的金额。`aws ec2 describe-reserved-instances-modifications` 用于确认状态;它的状态是 `fulfilled`,不是 `completed`。

当 RI 确实无法使用时,标准 RI 可以在 RI Marketplace 上挂牌(仅限美国卖家),或交换为等值或更高价值。可转换 RI 不能转售,只能交换——这才是灵活性的真正代价。

## 速查表

| 场景 | 购买建议 |
|---|---|
| 稳定 24/7 运行、无迁移计划的机群 | 标准 RI,1 年,区域级,All Upfront |
| 机群在 AZ 之间迁移 | 标准 RI,区域级范围 |
| 在同一实例族内变更大小 | 标准 RI(Linux 大小灵活性) |
| 12 个月内迁移到新实例族 | 可转换 RI,或 Compute Savings Plan |
| 突发型,每月运行时间 <40% | 按需实例 |
| EC2 + Lambda + Fargate 混合 | 优先选 Compute Savings Plan 而非 RI |
| 需要在一个 AZ 内保证容量 | 可用区级 RI |

在点击购买之前:确认覆盖率低于 85%,确认以秒为单位的期限,对 offering ID 执行 dry-run,并把 `End` 日期写进团队日历。然后在一个月内每周检查一次覆盖率 + 利用率。如果覆盖率没问题但利用率低于 70%,你下一次购买应该更小——而不是更大。

如果你更希望让别人来照看覆盖率报告和续订日期,这正是 awsgood.com 会连同定期成本审查一起处理的事情。

参考来源