Purchases a reserved instance. Reserved instances can be applied to automatically offset the bills of 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

Parameter Type Required Example Description
Action String Yes PurchaseReservedInstancesOffering

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

RegionId String Yes cn-hangzhou

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

ResourceGroupId String No rg-bp199lyny9b3****

The ID of the resource group.

ZoneId String No cn-hangzhou-g

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

ReservedInstanceName String No testReservedInstanceName

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://. It can contain letters, digits, colons (:), underscores (_), and hyphens (-).

InstanceType String Yes ecs.g5.large

The instance type of the instance. For more information, see Instance family.

Scope String No Zone

The scope of the reserved instance. Valid values:

  • Region: regional
  • Zone: zonal

Default value: Region.

InstanceAmount Integer No 3

The number of pay-as-you-go instances of the same instance type that the reserved instance can match. 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 match three ecs.g5.large pay-as-you-go instances.

OfferingType String No All Upfront

The payment option of the reserved instance. Valid values:

  • No Upfront
  • Partial Upfront
  • All Upfront

Default value: All Upfront.

Description String No testDescription

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.

Platform String No Linux

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.

Period Integer No 1

The validity period of the reserved instance.

Valid values: 1 and 3.

Default value: 1.

PeriodUnit String No Year

The unit of the validity period of the reserved instance.

Valid value: Year.

Default value: Year.

ClientToken String No 123e4567-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 it 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.

Tag.N.Key String No TestKey

The key of tag N of 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.Value String No TestValue

The value of tag N of 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.

Response parameters

Parameter Type Example Description
RequestId String 8C314443-AF0D-4766-9562-C83B7F1A3C8B

The ID of the request.

ReservedInstanceIdSets Array of String ecsri-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 code Error code Error message Description
400 InvalidInstanceType.ValueUnauthorized The specified InstanceType is not authorized. The error message returned because you are not authorized to use the specified instance type.
400 InvalidDescription.Malformed The 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://.
400 InvalidParameter.Conflict The specified region and cluster do not match. The error message returned because the specified region and cluster do not correspond to each other.
400 InvalidTagKey.Malformed The specified Tag.n.Key is not valid. The error message returned because the specified Tag.N.Key parameter is invalid.
400 RegionUnauthorized %s The 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.
400 Zone.NotOnSale %s The 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.
400 InvalidPeriodUnit.ValueNotSupported The specified parameter PeriodUnit is not valid. The error message returned because the specified PeriodUnit parameter is invalid.
400 InvalidTagValue.Malformed The specified Tag.n.Value is not valid. The error message returned because the specified Tag.N.Value parameter is invalid.
400 InvalidChargeType.ValueNotSupported ChargeType is not valid The error message returned because the specified ChargeType parameter is invalid.
400 InvalidInstanceType.ValueNotSupported The specified InstanceType beyond the permitted range. The error message returned because the specified InstanceType parameter is invalid.
400 InvalidInstanceType.ValueNotSupported The 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 this instance type.
403 OperationDenied The creation of Host to the specified Zone is not allowed. The error message returned because you are not authorized to create a dedicated host in the specified zone.
403 OperationDenied.NoStock The requested resource is sold out in the specified zone; try other types of resources or other regions and zones. The error message returned because requested resources are unavailable in the specified zone. Try another instance type or zone. You can call the DescribeZones operation to query available resources.
403 OperationDenied Sales of this resource are temporarily suspended in the specified region; please try again later. The error message returned because the requested resource is unavailable in the specified region. Try again later.
403 NodeControllerUnavailable The Node Controller is temporarily unavailable. The error message returned because the node controller is unavailable.
403 OperationDenied The 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.
403 InvalidParameter.ResourceOwnerAccount ResourceOwnerAccount is Invalid. The error message returned because the specified ResourceOwnerAccount parameter is invalid.
403 Zone.NotOpen The 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.
403 Zone.NotOnSale The 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.
403 InvalidParameter.NotMatch %s The error message returned because a specified parameter is invalid. Check whether parameter conflicts exist.
403 Account.Arrearage Your 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.
404 PaymentMethodNotFound No payment method has been registered on the account. The error message returned because you have not configured a payment method for your account.
500 InternalError The request processing has failed due to some unknown error. The error message returned because an internal error has occurred. Try again later. If the error persists, submit a ticket.
500 InternalError %s The error message returned because an internal error has occurred.
500 InternalError The 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. If the error persists, submit a ticket.

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