Purchases a reserved instance. Reserved instances can be automatically matched to pay-as-you-go instances to offset the bills of the pay-as-you-go instances.

Description

  • Before you call this operation, make sure that you fully understand the billing method of reserved instances. For more information, see Reserved instances.
  • Before you purchase a reserved instance, you can call the DescribeAvailableResource operation to query available instance resources.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

ParameterTypeRequiredExampleDescription
ActionStringYesPurchaseReservedInstancesOffering

The operation that you want to perform. Set the value to PurchaseReservedInstancesOffering.

RegionIdStringYescn-hangzhou

The ID of the region in which to purchase the reserved instance. You can call the DescribeRegions operation to query the most recent region list.

Tag.N.KeyStringNoTestKey

The key of tag N to add to the reserved instance. Valid values of N: 1 to 20. The tag key cannot be an empty string. It can be up to 128 characters in length and cannot contain http:// or https://. It cannot start with acs: or aliyun.

Tag.N.ValueStringNoTestValue

The value of tag N to add to the reserved instance. Valid values of N: 1 to 20. The tag value cannot be an empty string. It can be up to 128 characters in length and cannot contain http:// or https://. It cannot start with acs: or aliyun.

ResourceGroupIdStringNorg-bp199lyny9b3****

The ID of the resource group.

ZoneIdStringNocn-hangzhou-g

The ID of the zone in which to purchase the reserved instance. This parameter is required when Scope is set to Zone. You can call the DescribeZones operation to query the most recent zone list.

ReservedInstanceNameStringNotestReservedInstanceName

The name of the reserved instance. The name must be 2 to 128 characters in length. It must start with a letter and cannot start with http:// or https://. The name can contain digits, letters, colons (:), underscores (_), and hyphens (-).

InstanceTypeStringYesecs.g5.large

The instance type. For more information, see Instance families.

ScopeStringNoZone

The scope of the reserved instance. Valid values:

  • Region: regional
  • Zone: zonal

Default value: Region.

InstanceAmountIntegerNo3

The number of pay-as-you-go instances of the same instance type that the reserved instance can be matched to at the same time. Valid values: 1 to 50.

For example, if InstanceAmount is set to 3 when InstanceType is set to ecs.g5.large, the reserved instance can be matched to three ecs.g5.large pay-as-you-go instances at the same time.

OfferingTypeStringNoAll Upfront

The payment option of the reserved instance. Valid values:

  • No Upfront
  • Partial Upfront
  • All Upfront

Default value: All Upfront.

DescriptionStringNotestDescription

The description of the reserved instance. The description must be 2 to 256 characters in length and cannot start with http:// or https://.

This parameter is empty by default.

PlatformStringNoLinux

The operating system of the image used by the instance. Valid values:

  • Windows: Windows Server operating system
  • Linux: Linux and UNIX-like operating system

Default value: Linux.

PeriodIntegerNo1

The term of the reserved instance.

Valid values: 1 and 3.

Default value: 1.

PeriodUnitStringNoYear

The unit of the term of the reserved instance.

Valid value: Year.

Default value: Year.

ClientTokenStringNo123e4567-e89b-12d3-a456-426655440000

The client token that is used to ensure the idempotence of the request. You can use the client to generate the value, but you must make sure that the value is unique among different requests. The ClientToken value can contain only ASCII characters and cannot exceed 64 characters in length. For more information, see How to ensure idempotence.

AutoRenewBooleanNotrue

Specifies whether to enable auto-renewal for the reserved instance.

true: enables auto-renewal for the reserved instance. false: does not enable auto-renewal for the reserved instance.

AutoRenewPeriodIntegerNo1

The auto-renewal term of the reserved instance. This parameter takes effect only when AutoRenew is set to true.

Valid values: 12, 36.

Default value when PeriodUnit is set to Year: 12

Response parameters

ParameterTypeExampleDescription
RequestIdString8C314443-AF0D-4766-9562-C83B7F1A3C8B

The ID of the request.

ReservedInstanceIdSetsArray of Stringecsri-2ze53qonjqxg7r****

The IDs of the reserved instances.

Examples

Sample requests

https://ecs.aliyuncs.com/?Action=PurchaseReservedInstancesOffering
&RegionId=cn-hangzhou
&Scope=Zone
&ZoneId=cn-hangzhou-a
&ReservedInstanceName=test
&InstanceType=ecs.g5.2xlarge
&InstanceAmount=1
&OfferingType=AllUpfront
&Period=1
&PeriodUnit=Year
&<Common request parameters>

Sample success responses

XML format

HTTP/1.1 200 OK
Content-Type:application/xml

<PurchaseReservedInstancesOfferingResponse>
    <RequestId>8C314443-AF0D-4766-9562-C83B7F1A3C8B</RequestId>
    <ReservedInstanceIdSets>
        <ReservedInstanceId>ecsri-2ze53qonjqxg7r****</ReservedInstanceId>
    </ReservedInstanceIdSets>
</PurchaseReservedInstancesOfferingResponse>

JSON format

HTTP/1.1 200 OK
Content-Type:application/json

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

Error codes

HTTP status codeError codeError messageDescription
400InvalidInstanceType.ValueUnauthorizedThe specified InstanceType is not authorized.The error message returned because you are not authorized to use the specified instance type.
400InvalidDescription.MalformedThe specified parameter "Description" is not valid.The error message returned because the specified Description parameter is invalid. The description must be 2 to 256 characters in length and cannot start with http:// or https://.
400InvalidParameter.ConflictThe specified region and cluster do not match.The error message returned because the specified region and cluster do not correspond to each other.
400InvalidTagKey.MalformedThe specified Tag.n.Key is not valid.The error message returned because the specified Tag.N.Key parameter is invalid.
400RegionUnauthorized%sThe error message returned because you are not authorized to perform the operation in the specified region. %s is a variable. An error message is dynamically returned based on call conditions.
400Zone.NotOnSale%sThe error message returned because the requested resources are unavailable in the specified zone. %s is a variable. An error message is dynamically returned based on call conditions.
400InvalidPeriodUnit.ValueNotSupportedThe specified parameter PeriodUnit is not valid.The error message returned because the specified PeriodUnit parameter is invalid.
400InvalidTagValue.MalformedThe specified Tag.n.Value is not valid.The error message returned because the specified Tag.N.Value parameter is invalid.
400InvalidChargeType.ValueNotSupportedChargeType is not valid.The error message returned because the specified billing method is not supported. Set a supported billing method.
400InvalidInstanceType.ValueNotSupportedThe specified InstanceType beyond the permitted range.The error message returned because the specified InstanceType parameter is invalid.
400InvalidInstanceType.ValueNotSupportedThe specified InstanceType does not exist or beyond the permitted range.The error message returned because the specified InstanceType parameter does not exist or because you are not authorized to manage instances of the instance type.
403OperationDeniedThe creation of Host to the specified Zone is not allowed.The error message returned because you are not authorized to create dedicated hosts in the specified zone.
403OperationDenied.NoStockThe requested resource is sold out in the specified zone; try other types of resources or other regions and zones.The error message returned because the requested resources are unavailable in the specified zone. Try a different instance type or zone. You can call the DescribeZones operation to query available resources.
403OperationDeniedSales of this resource are temporarily suspended in the specified region; please try again later.The error message returned because the requested resources are unavailable in the specified region. Try again later.
403NodeControllerUnavailableThe Node Controller is temporarily unavailable.The error message returned because the node controller is unavailable.
403OperationDeniedThe resource is out of usage.The error message returned because the instance is not in the Running state. Start the instance or check whether the specified operation is valid.
403InvalidParameter.ResourceOwnerAccountResourceOwnerAccount is Invalid.The error message returned because the specified ResourceOwnerAccount parameter is invalid.
403Zone.NotOpenThe specified zone is not granted to you to buy resources yet.The error message returned because you are not authorized to purchase resources in the specified zone.
403Zone.NotOnSaleThe specified zone is not available for purchase.The error message returned because the requested resources are unavailable in the specified zone. Try other instance types or select other regions or zones.
403InvalidParameter.NotMatch%sThe error message returned because a specified parameter is invalid. Check whether parameter conflicts exist.
403Account.ArrearageYour account has been in arrears.The error message returned because your account balance is insufficient. Add funds to your Alibaba Cloud account and try again.
404PaymentMethodNotFoundNo payment method has been registered on the account.The error message returned because you have not configured a payment method for your account.
500InternalErrorThe request processing has failed due to some unknown error.The error message returned because an internal error has occurred. Try again later.
500InternalError%sThe error message returned because an internal error has occurred.
500InternalErrorThe request processing has failed due to some unknown error, exception or failure.The error message returned because an internal error has occurred. Try again later.

For a list of error codes, visit the API Error Center.