全部產品
Search
文件中心

Elastic Compute Service:PurchaseReservedInstancesOffering - 購買預留執行個體券

更新時間:Apr 04, 2026

本介面用於購買一張預留執行個體券,支援您購買一張地區級或者可用性區域級的預留執行個體券來抵扣對應規格的隨用隨付執行個體賬單。

介面說明

請確保在使用該介面前,已充分瞭解預留執行個體券的收費方式和價格

  • 請確保在使用該介面前,您已充分瞭解預留執行個體券的計費規則。詳情請參見預留執行個體券

  • 在所有地區下,您最多可以持有 20 張地區級預留執行個體券。

  • 單個可用性區域下,您最多可以持有 20 張可用性區域級預留執行個體券。

請求樣本

  • 在杭州地區下購買一張時間長度 1 年的地區級預留執行個體券,用來抵扣 3 台執行個體規格為 ecs.g5.large、作業系統為 Linux 的隨用隨付執行個體賬單。

"RegionId":"cn-hangzhou", //設定地區為杭州
"InstanceType":"ecs.g5.large", //設定執行個體規格
"Scope":"Region", //設定預留執行個體券的範圍為地區級
"InstanceAmount":3, //表示預留執行個體券可以同時匹配同規格隨用隨付執行個體的數量為 3 台
"OfferingType":"All Upfront", //預設值,表示付款類型為全預付
"Platform":"Linux", //執行個體使用的鏡像的作業系統類型為 Linux 或者類 Unix 類型的作業系統
"Period":1, //購買預留執行個體券的時間長度為 1 年
"PeriodUnit":"Year", //設定時間長度單位為年
  • 在杭州地區的可用性區域 H 下購買一張時間長度 2 年的可用性區域級預留執行個體券,用來抵扣 5 台執行個體規格為 ecs.g5.large、作業系統為 Windows 的隨用隨付執行個體賬單。

"RegionId":"cn-hangzhou",
"ZoneId":"cn-hangzhou-h", //設定可用性區域為可用性區域 H
"InstanceType":"ecs.g5.large",
"Scope":"Zone", //設定預留執行個體券的範圍為可用性區域級
"InstanceAmount":5, //表示預留執行個體券可以同時匹配同規格隨用隨付執行個體的數量為 5 台
"OfferingType":"All Upfront",
"Platform":"Windows", //執行個體使用的鏡像的作業系統類型為 Windows
"Period":2, //購買預留執行個體券的時間長度為 2 年
"PeriodUnit":"Year", //設定時間長度單位為年

調試

您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。

調試

授權資訊

下表是API對應的授權資訊,可以在RAM權限原則語句的Action元素中使用,用來給RAM使用者或RAM角色授予調用此API的許可權。具體說明如下:

  • 操作:是指具體的許可權點。

  • 存取層級:是指每個操作的存取層級,取值為寫入(Write)、讀取(Read)或列出(List)。

  • 資源類型:是指操作中支援授權的資源類型。具體說明如下:

    • 對於必選的資源類型,用前面加 * 表示。

    • 對於不支援資源級授權的操作,用全部資源表示。

  • 條件關鍵字:是指雲產品自身定義的條件關鍵字。

  • 關聯操作:是指成功執行操作所需要的其他許可權。操作者必須同時具備關聯操作的許可權,操作才能成功。

操作

存取層級

資源類型

條件關鍵字

關聯操作

ecs:PurchaseReservedInstancesOffering

create

*ReservedInstance

acs:ecs:{#regionId}:{#accountId}:reservedinstance/*

請求參數

名稱

類型

必填

描述

樣本值

RegionId

string

地區 ID。您可以調用 DescribeRegions 擷取最新的阿里雲地區列表。

cn-hangzhou

Tag

array<object>

標籤數組。數組長度:0~20。

object

Key

string

預留執行個體券的標籤鍵。不允許為空白字串,最多支援 128 個字元,不能以aliyunacs:開頭,不能包含http://或者https://

TestKey

Value

string

預留執行個體券的標籤值。則不允許為空白字串,最多支援 128 個字元,不能以aliyunacs:開頭,不能包含http://或者https://

TestValue

ResourceGroupId

string

資源群組 ID。

rg-bp199lyny9b3****

ZoneId

string

可用性區域 ID,當ScopeZone時生效且必填。您可以調用 DescribeZones 擷取可用性區域列表。

cn-hangzhou-g

ReservedInstanceName

string

預留執行個體券的名稱。長度為 2~128 個英文或中文字元,必須以大小寫字母或中文開頭,不能以 http:// 和 https:// 開頭。可以包含數字、半形冒號(:)、底線(_)或者短劃線(-)。

testReservedInstanceName

InstanceType

string

預留執行個體券可以匹配的執行個體規格。

說明

適用的執行個體規格持續更新,詳情請參見預留執行個體券概述

ecs.g5.large

Scope

string

預留執行個體券的範圍。取值範圍:

  • Region:地區層級。

  • Zone:可用性區域層級。

預設值:Region。

Zone

InstanceAmount

integer

預留執行個體券可以同時匹配同規格隨用隨付執行個體的數量。取值範圍:1~50。

預設值:1。

3

OfferingType

string

預留執行個體券的付款類型。取值範圍:

  • No Upfront:零預付。

  • Partial Upfront:部分預付。

  • All Upfront:全預付。

預設值:All Upfront。

All Upfront

Description

string

預留執行個體券的描述。長度為 2~256 個英文或中文字元,不能以 http://和 https://開頭。

預設值:空。

testDescription

Platform

string

執行個體使用的鏡像的作業系統類型。取值範圍:

  • Windows:Windows Server 類型的作業系統。

  • Linux:Linux 及類 Unix 類型的作業系統。

預設值:Linux。

Linux

Period

integer

購買預留執行個體券的時間長度。

取值範圍:1、3。

預設值:1。

1

PeriodUnit

string

購買預留執行個體券的時間長度單位。

取值範圍:Year。

預設值:Year。

Year

ClientToken

string

保證請求等冪性。從您的用戶端產生一個參數值,確保不同請求間該參數值唯一。ClientToken 只支援 ASCII 字元,且不能超過 64 個字元。更多資訊,請參見如何保證等冪性

123e4567-e89b-12d3-a456-426655440000

AutoRenew

boolean

是否要自動續約。可選值:

  • true:自動續約。

  • false(預設):不自動續約。

true

AutoRenewPeriod

integer

每次自動續約的時間長度,單位為月。當參數 AutoRenew 取值 True 時,該參數才生效。

AutoRenewPeriod 取值範圍:12,36。

當 PeriodUnit=Year,預設值為 12。

1

StartTime

string

預留執行個體券的指定生效時間。按照ISO 8601標準表示,使用 UTC+0 時間。格式為:yyyy-MM-ddTHHZ

說明

生效時間不填寫時,預設從目前時間的整點時間開始生效。例如,你在 2024-11-01 13:45:35 成功購買,生效時間則為 2024-11-01 13:00:00。

2024-07-04T15Z

返回參數

名稱

類型

描述

樣本值

object

RequestId

string

請求 ID。

8C314443-AF0D-4766-9562-C83B7F1A3C8B

ReservedInstanceIdSets

object

ReservedInstanceId

array

預留執行個體券 ID 列表。

string

預留執行個體券 ID。

ecsri-2ze53qonjqxg7r****

OrderId

string

訂單 ID。

23841229****

樣本

正常返回樣本

JSON格式

{
  "RequestId": "8C314443-AF0D-4766-9562-C83B7F1A3C8B",
  "ReservedInstanceIdSets": {
    "ReservedInstanceId": [
      "ecsri-2ze53qonjqxg7r****"
    ]
  },
  "OrderId": "23841229****"
}

異常返回樣本

JSON格式

{
    "RequestId": "51AB7717-6E1A-4D1D-A44D-54CBxxxxxxxx",
    "ReservedInstanceId":"ri-instance"
}

錯誤碼

HTTP status code

錯誤碼

錯誤資訊

描述

400 InvalidStartTime.ScopeNotMatch Zonal reservedInstance not supported for scheduled creating.
400 InvalidInstanceType.ValueUnauthorized The specified InstanceType is not authorized.
400 InvalidDescription.Malformed The specified parameter "Description" is not valid. 指定的資源描述格式不合法。長度為2-256個字元,不能以http://和https://開頭。
400 InvalidParameter.Conflict The specified region and cluster do not match. 指定的地區與指定的叢集不匹配。
400 InvalidTagKey.Malformed The specified Tag.n.Key is not valid. 指定的標籤鍵參數有誤。
400 InvalidPeriodUnit.ValueNotSupported The specified parameter PeriodUnit is not valid. 參數 PeriodUnit 無效。
400 InvalidTagValue.Malformed The specified Tag.n.Value is not valid. 指定的標籤值參數有誤。
400 InvalidChargeType.ValueNotSupported ChargeType is not valid.
400 InvalidParameter.Scope The specified parameter 'Scope' is invalid.
400 InvalidReservedInstanceStatus.ValueNotSupported ReservedInstance status is not supported.
400 InvalidReservedInstanceOfferingType.ValueNotSupported The OfferingType is not supported.
400 InvalidReservedInstanceOfferingClass.ValueNotSupported The OfferingClass is not supported.
400 MissingParameter.ZoneId The specified zoneId should be not empty.
400 MissingParameter.InstanceType The instanceType should be not empty.
400 MissingParameter.ReservedInstanceId The ids of reservedInstance can not be empty.
400 MissingParameter.ReservedInstanceConfiguration The configurations of reservedInstance can not be empty.
400 InvalidParameter.SplitOrMerge The Many-to-many of modification is not supported.
400 MissingParameter.InstanceTypeAndAmountBothEmpty The instanceType and amount can not be both empty.
400 InvalidReservedInstancePlatform.ValueNotSupported The Platform is not supported.
400 InvalidParameter.ReservedInstanceName ReservedInstanceName is invalid.
400 InvalidReservedInstanceZone.ValueNotSupported The zoneId is not exist.
400 OperationDenied The specified InstanceType or Zone is not authorized for current user.
400 InvalidInstanceType.ValueNotSupported The specified InstanceType beyond the permitted range. 指定的執行個體規格不合法(超出可選範圍)。
500 InternalError The request processing has failed due to some unknown error.
403 OperationDenied The creation of Host to the specified Zone is not allowed. 無法在指定可用性區域建立專用宿主機。
403 OperationDenied.NoStock The requested resource is sold out in the specified zone; try other types of resources or other regions and zones. 庫存不足。
403 NodeControllerUnavailable The Node Controller is temporarily unavailable.
403 InvalidParameter.ResourceOwnerAccount ResourceOwnerAccount is Invalid. 指定的 ResourceOwnerAccount 不合法。
403 Zone.NotOpen The specified zone is not granted to you to buy resources yet.
403 Zone.NotOnSale The specified zone is not available for purchase. 指定可用性區域已經售罄,請您更換執行個體規格或者更換地區建立。
403 Account.Arrearage Your account has been in arrears.
403 InvalidStartTime.MalFormed The specified StartTime is not valid.
403 InvalidStartTime.NotSupported The specified startTime is not supported.
403 RegionUnauthorized You are not authorized to perform the operation in the specified region. 該地區未授權。
404 InvalidZoneId.NotFound The ZoneId provided does not exist in our records.
404 PaymentMethodNotFound No payment method has been registered on the account.

訪問錯誤中心查看更多錯誤碼。

變更歷史

更多資訊,參考變更詳情