本接口用于购买一张预留实例券,支持您购买一张地域级或者可用区级的预留实例券来抵扣对应规格的按量付费实例账单。
接口说明
请确保在使用该接口前,已充分了解预留实例券的收费方式和价格。
请确保在使用该接口前,您已充分了解预留实例券的计费规则。详情请参见预留实例券。
在所有地域下,您最多可以持有 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代码示例。
调试
授权信息
|
操作 |
访问级别 |
资源类型 |
条件关键字 |
关联操作 |
|
ecs:PurchaseReservedInstancesOffering |
create |
*ReservedInstance
|
无 | 无 |
请求参数
|
名称 |
类型 |
必填 |
描述 |
示例值 |
| RegionId |
string |
是 |
地域 ID。您可以调用 DescribeRegions 获取最新的阿里云地域列表。 |
cn-hangzhou |
| Tag |
array<object> |
否 |
标签数组。数组长度:0~20。 |
|
|
object |
否 |
|||
| Key |
string |
否 |
预留实例券的标签键。不允许为空字符串,最多支持 128 个字符,不能以 |
TestKey |
| Value |
string |
否 |
预留实例券的标签值。则不允许为空字符串,最多支持 128 个字符,不能以 |
TestValue |
| ResourceGroupId |
string |
否 |
资源组 ID。 |
rg-bp199lyny9b3**** |
| ZoneId |
string |
否 |
可用区 ID,当 |
cn-hangzhou-g |
| ReservedInstanceName |
string |
否 |
预留实例券的名称。长度为 2~128 个英文或中文字符,必须以大小写字母或中文开头,不能以 http:// 和 https:// 开头。可以包含数字、半角冒号(:)、下划线(_)或者短划线(-)。 |
testReservedInstanceName |
| InstanceType |
string |
是 |
预留实例券可以匹配的实例规格。 说明
适用的实例规格持续更新,详情请参见预留实例券概述。 |
ecs.g5.large |
| Scope |
string |
否 |
预留实例券的范围。取值范围:
默认值:Region。 |
Zone |
| InstanceAmount |
integer |
否 |
预留实例券可以同时匹配同规格按量付费实例的数量。取值范围:1~50。 默认值:1。 |
3 |
| OfferingType |
string |
否 |
预留实例券的付款类型。取值范围:
默认值:All Upfront。 |
All Upfront |
| Description |
string |
否 |
预留实例券的描述。长度为 2~256 个英文或中文字符,不能以 http://和 https://开头。 默认值:空。 |
testDescription |
| Platform |
string |
否 |
实例使用的镜像的操作系统类型。取值范围:
默认值: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 |
| AutoRenewPeriod |
integer |
否 |
每次自动续费的时长,单位为月。当参数 AutoRenew 取值 True 时,该参数才生效。 AutoRenewPeriod 取值范围:12,36。 当 PeriodUnit=Year,默认值为 12。 |
1 |
| StartTime |
string |
否 |
预留实例券的指定生效时间。按照ISO 8601标准表示,使用 UTC+0 时间。格式为: 说明
生效时间不填写时,默认从当前时间的整点时间开始生效。例如,你在 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. |
访问错误中心查看更多错误码。
变更历史
更多信息,参考变更详情。