You can call this operation to purchase a reserved instance. Reserved instances can be used to automatically offset bills of pay-as-you-go instances.

Description

  • Before you call this operation, make sure that you have fully understood the billing method of reserved instances. For more information, see Reserved instance billing.
  • 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.

InstanceType String Yes ecs.g5.large

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

RegionId String Yes cn-hangzhou

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

Scope String No Zone

The scope of the reserved instance. Valid values:

  • Region: regional
  • Zone: zonal

Default value: Region

ZoneId String No cn-hangzhou-g

The zone ID of the instance. If the Scope parameter is set to Zone, you must set the zone ID. For more information, call the DescribeZones operation to query the most recent zone list.

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 for an ecs.g5.large reserved instance, the reserved instance can match three ecs.g5.large pay-as-you-go instances.

Platform String No Linux

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

  • Windows: Windows Server operating systems
  • Linux: Linux and Unix-like operating systems
PeriodUnit String No Year

The term unit of the reserved instance. Valid value: Year.

Period Integer No 1

The term of the reserved instance. Valid values: 1 and 3.

Default: 1

OfferingType String No All Upfront

The payment option of the reserved instance. Default value: All Upfront. Valid values:

  • No Upfront: No upfront payment is required.
  • Partial Upfront: A portion of upfront payment is required.
  • All Upfront: Full upfront payment is required.
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 (-).

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.

ResourceGroupId String No rg-bp199lyny9b3****

The ID of the resource group.

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 ensure that it is unique among different requests. The ClientToken value can only contain ASCII characters and cannot exceed 64 characters in length. For more information, see How to ensure idempotence.

Tag.N.Key String No TestKey

The tag key of the reserved instance.

Tag.N.Value String No TestValue

The tag value of the reserved instance.

Response parameters

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

The ID of the request.

ReservedInstanceIdSets List ecsri-2ze53qonjqxg7r****

The ID of the reserved instance.

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

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

JSON format

{
    "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 is invalid. The description must be 2 to 256 characters in length and cannot start with http:// or https://.
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 the requested resource is insufficient.
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 problem persists, submit a ticket.
403 OperationDenied Sales of this resource are temporarily suspended in the specified region; please try again later. The error message returned because this resource is unavailable in the specified region. Try again later.
400 InvalidParameter.Conflict The specified region and cluster do not match. The error message returned because the specified region does not match the specified cluster.
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 a proper operation is performed.
404 PaymentMethodNotFound No payment method has been registered on the account. The error message returned because you have not configured the payment method for your account.
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. Change the instance type or select a different zone.
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 the specified region is not authorized.
500 InternalError %s The error message returned because an unknown internal error occurs.
400 Zone.NotOnSale %s The error message returned because the service is temporarily unavailable in this zone.
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.
403 InvalidParameter.NotMatch %s The error message returned because the specified parameters are invalid. Check whether the parameters conflict with each other.
403 Account.Arrearage Your account has been in arrears. The error message returned because your account balance is insufficient. Top up your account before proceeding.
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.
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 problem persists, submit a ticket.
400 InvalidInstanceType.ValueNotSupported The specified InstanceType does not exist or beyond the permitted range. The error message returned because the specified instance type does not exist or you are not authorized to manage the instance type.

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