All Products
Search
Document Center

Elastic Compute Service:CreateCapacityReservation

Last Updated:Oct 09, 2026

Creates a capacity reservation by specifying the instance type, total number of instances, effective mode, and zone.

Operation description

Operation description

You can use the capacity reservation service to specify property settings such as the zone and instance type. The system reserves resources that match the specified property settings in a private pool. For more information, see Overview of immediate capacity reservations.

  • Currently, the service only supports the immediate effective mode. After you purchase an immediate capacity reservation, the instance type is subject to pay-as-you-go standard billing regardless of whether pay-as-you-go instances are actually created, until you manually release it or the system automatically releases it upon expiration.
    • You can configure the private pool capacity settings when creating an instance by invoking CreateInstance or RunInstances, or modify the private pool capacity options of an instance by invoking ModifyInstanceAttachmentAttributes. After an instance successfully matches the private pool capacity, you are billed for resources such as the instance type, cloud disks, and public bandwidth based on your instance configurations.

    • If no pay-as-you-go instances are actually created, you are billed only for the instance type.

  • Bills for matched instances and unused capacity of immediate capacity reservations can be offset by savings plans or regional reserved instances on an hourly basis, but cannot be offset by zonal reserved instances. We recommend that you purchase reserved instances or savings plans first. Using immediate capacity reservations under the coverage of reserved instances or savings plans allows you to obtain guaranteed resources for free.

Note

You can invoke the API only to create immediate capacity reservations. You can create immediate capacity reservations or scheduled capacity reservations in the ECS console. For more information, see Resource Assurance.

Try it now

Try this API in OpenAPI Explorer, no manual signing needed. Successful calls auto-generate SDK code matching your parameters. Download it with built-in credential security for local usage.

Test

RAM authorization

The table below describes the authorization required to call this API. You can define it in a Resource Access Management (RAM) policy. The table's columns are detailed below:

  • Action: The actions can be used in the Action element of RAM permission policy statements to grant permissions to perform the operation.

  • API: The API that you can call to perform the action.

  • Access level: The predefined level of access granted for each API. Valid values: create, list, get, update, and delete.

  • Resource type: The type of the resource that supports authorization to perform the action. It indicates if the action supports resource-level permission. The specified resource must be compatible with the action. Otherwise, the policy will be ineffective.

    • For APIs with resource-level permissions, required resource types are marked with an asterisk (*). Specify the corresponding Alibaba Cloud Resource Name (ARN) in the Resource element of the policy.

    • For APIs without resource-level permissions, it is shown as All Resources. Use an asterisk (*) in the Resource element of the policy.

  • Condition key: The condition keys defined by the service. The key allows for granular control, applying to either actions alone or actions associated with specific resources. In addition to service-specific condition keys, Alibaba Cloud provides a set of common condition keys applicable across all RAM-supported services.

  • Dependent action: The dependent actions required to run the action. To complete the action, the RAM user or the RAM role must have the permissions to perform all dependent actions.

Action

Access level

Resource type

Condition key

Dependent action

ecs:CreateCapacityReservation

create

*CapacityReservation

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

None None

Request parameters

Parameter

Type

Required

Description

Example

RegionId

string

Yes

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

cn-hangzhou

ResourceGroupId

string

No

The ID of the enterprise resource group to which the capacity reservation belongs.

rg-bp67acfmxazb4p****

Tag

array<object>

No

The list of tags bound to the capacity reservation.

object

No

The tag.

Key

string

No

The tag key of the capacity reservation. Valid values of N: 1 to 20. If this parameter is specified, it cannot be an empty string. The tag key can be up to 128 characters in length, and cannot start with aliyun or acs:, or contain http:// or https://.

TestKey

Value

string

No

The tag value of the capacity reservation. Valid values of N: 1 to 20. If this parameter is specified, it can be an empty string. The tag value can be up to 128 characters in length, and cannot start with acs:, or contain http:// or https://.

TestValue

ClientToken

string

No

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 contain only ASCII characters and cannot exceed 64 characters in length. For more information, see How to ensure idempotence.

0c593ea1-3bea-11e9-b96b-88e9fe637760

PrivatePoolOptions.Name

string

No

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

crpTestName

Description

string

No

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

Default value: empty.

This is description.

PrivatePoolOptions.MatchCriteria

string

No

The type of the private pool generated after the capacity reservation takes effect. Valid values:

  • Open: open mode. When you start an instance, the system automatically matches the capacity of an open private pool. If no eligible private pool capacity is available, the instance uses public pool resources.

  • Target: dedicated mode. The instance uses the capacity of the specified private pool. If the capacity of the private pool is unavailable, the instance fails to start.

Default value: Open.

Open

InstanceAmount

integer

Yes

The total number of instances to be reserved for a single instance type.

2

InstanceType

string

Yes

The instance type. Currently, you can configure the capacity reservation settings for only one instance type. You can invoke the DescribeInstanceTypes operation to query the instance types provided by Elastic Compute Service (ECS).

ecs.g6.xlarge

StartTime

string

No

The effective mode of the capacity reservation. Currently, calling the API only supports setting this parameter to take effect immediately. Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC.

Note

If this parameter is not specified, the capacity reservation takes effect immediately.

2021-10-30T05:32:00Z

EndTime

string

No

The expiration time of the capacity reservation. Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC. For more information, see ISO 8601.

2021-10-30T06:32:00Z

EndTimeType

string

No

The expiration mode of the capacity reservation. Valid values:

  • Limited: releases the reservation at a specified time. You must also specify the EndTime parameter.

  • Unlimited: manual release. No time limit is imposed.

Unlimited

Platform

string

No

The operating system type of the image used by the instance. This parameter corresponds to the Platform parameter of regional reserved instances. If the operating system type of the capacity reservation matches that of the regional reserved instances, you can use the regional reserved instances to offset the bills for the unused capacity of the capacity reservation. Valid values:

  • Windows: Windows Server operating systems.

  • Linux: Linux and Unix-like operating systems.

Default value: Linux.

Note

This parameter is not available.

Linux

InstanceChargeType

string

No

The billing method of the instance. Currently, only PostPaid (pay-as-you-go) is supported. Default value: PostPaid.

PostPaid

ZoneId

array

Yes

The zone ID of the region to which the capacity reservation belongs. Currently, you can create a capacity reservation in only one zone.

cn-hangzhou-h

string

No

The zone ID of the region to which the capacity reservation belongs.

cn-hangzhou-h

Response elements

Element

Type

Description

Example

object

PrivatePoolOptionsId

string

The ID of the capacity reservation.

crp-bp67acfmxazb4****

RequestId

string

The request ID.

473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E

Examples

Success response

JSON format

{
  "PrivatePoolOptionsId": "crp-bp67acfmxazb4****",
  "RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E"
}

Error codes

HTTP status code

Error code

Error message

Description

400 InvalidParameter.RegionId The specified RegionId is invalid. The specified region does not exist or is unavailable.
400 NoStock The stock in the availability zone is insufficient. The stock in the availability zone is insufficient.
400 MissingParameter The input parameter StartTime is missing.
400 OperationDenied The specified instanceType or zone is not available or not authorized. Specified specifications or Availability Zones are not available
400 MissingParameter.RegionId The specified RegionId should not be null. The RegionId parameter is required.
400 InvalidStartTime.NotSupported The specified StartTime should be within 180 calendar days from the current date, and you must specify a precision to hour. The specified StartTime value is out of range.
400 InvalidStartTime.MalFormed The specified StartTime is out of the permitted range. The specified StartTime value exceeds the maximum allowed value.
400 Invalid.PrivatePoolOptionsName.MalFormed The specified PrivatePoolOptions.Name is not valid. The specified PrivatePoolOptions.Name is invalid
400 Invalid.ZoneId The specified ZoneId is not valid. The specified ZoneId is invalid.
400 Invalid.InstanceType The specified InstanceType is not valid. The specified InstanceType is illegal.
400 DedicatedHostNotSupported DedicatedHost is not supported for PrivatePool. The private pool does not support dedicated hosts.
400 SpotNotSupported Spot is not supported for PrivatePool. The private pool does not support spot instances.
400 ClassicNetworkNotSupported Classic network is not supported for PrivatePool. The private pool does not support instances in the classic network.
400 Invalid.InstanceId Instance does not exist. The specified instance does not exist.
400 Invalid.PrivatePoolOptions.MatchCriteria Target mode does not support this operation. The operation is not supported while the PrivatePoolOptions.MatchCriteria parameter is set to Target.
400 MissingParameter.PrivatePoolOptions.Id The specified PrivatePoolOptions.Id should not be null. The PrivatePoolOptions.Id parameter is required.
400 Invalid.PrivatePoolOptions.Id The PrivatePool does not exist. The private pool does not exist.
400 Invalid.InstanceChargeType The InstanceChargeType does not match the PrivatePool. The instance billing method and the private pool do not match.
400 Invalid.PrivatePoolOptions.status The PrivatePool has been used up. The resource is exhausted.
400 InvalidPlatform.ValueNotSupported The Platform does not match the PrivatePool. The specified Platform parameter does not match the private pool.
400 InvalidAliUid The PrivatePool does not belong to the user of the Instance. The specified private pool does not belong to the user who attempted to create the instance.
400 MissingParameter.PackageType The specified parameter "PackageType" can not be empty. The PackageType parameter cannot be empty.
400 MissingParameter.PrivatePoolOptions.Ids The specified parameter "PrivatePoolOptions.Ids" can not be empty. Specifies that the parameter "PrivatePoolOptions.ids" cannot be empty.
400 MissingParameter.InstanceCpuCoreCount The specified parameter "InstanceCpuCoreCount" can not be empty. The specified parameter 'InstanceCpuCocount' cannot be empty.
400 MissingParameter.InstanceAmount The specified parameter "InstanceAmount" can not be empty. The specified parameter InstanceAmount cannot be empty.
400 MissingParameter.InstanceCpuCoreCountOrInstanceAmount The specified parameter "InstanceCpuCoreCount" and "InstanceAmount" must not be empty at the same time. The specified parameter InstanceCpuCoreCount and InstanceAmount cannot be both empty.
400 Invalid.TooManyPrivatePoolOptions.Ids Too many PrivatePoolOptions.Ids in this request. The number of specified private pool IDs exceeds the upper limit.
400 Invalid.TooManyZoneIds Too many ZoneIds in the request. The number of specified zone IDs exceeds the upper limit.
400 Invalid.TooManyInstanceTypes Too many InstanceTypes in the request. The number of specified instance types exceeds the upper limit.
400 Invalid.TooManyUnpaidPrivatePool Too many PrivatePools create but still unpaid. Multiple private pools are created but not paid.
400 Invalid.InstanceCpuCoreCountOrInstanceAmount Both InstanceCpuCoreCount and InstanceAmount are provided. The InstanceCpuCoreCount and InstanceAmount parameters cannot be both specified.
400 Invalid.PrivatePoolOptions.Ids The specified parameter "PrivatePoolOptions.Ids" exist invalid element Id. The specified private pool ID does not exist.
400 Invalid.PackageType The specified parameter "PackageType" is invalid. The specified parameter PackageType is invalid.
400 Invalid.PrivatePool.Purchase The PrivatePool has already paid. The private pool is already paid.
400 Invalid.AssuranceTimes.NotSupported The value of AssuranceTimes is not supported. The specified AssuranceTimes parameter is invalid.
400 RepeatStartPrivatePool PrivatePool has already been started. The private pool is already started.
400 Invalid.TimeSlot The param time slot is invalid. Parameter TimeSlot is invalid.
400 Invalid.EndTime The specified parameter "EndTime" is not valid. The specified EndTime parameter is illegal.
400 StartTime.NotNeed The specified parameter "StartTime" should leave empty. The specified parameter "StartTime" should be empty.
400 AccountForbidden.ProductCreationLimited The commodity must be officially operated by Aliyun and in pay-as-you-go billing method. Enterprise cloud migration customers can purchase only pay-as-you-go ECS instances and cannot purchase third-party products such as images provided by Alibaba Cloud Marketplace. Check the parameters and retry with valid parameters.
400 RegionUnauthorized There is no authority to create private pool in the specified region. The user is not authorized to create instances in the specified region.
400 PriceNotFound The price of your queried resource is not available now, please try other resources. The price of the specified resource does not exist. Modify the parameter value and try again later.
500 InternalError The request processing has failed due to some unknown error, exception or failure. An internal error has occurred. Try again later.
403 Zone.NotOpen The specified zone is not granted to you to buy resources yet.
403 InvalidResourceType.NotSupported %s The specified resource combination does not exist. Change to another zone or specification.
403 OperationDenied.NoStock The resource is out of stock in the specified zone. Please try other types, or choose other regions and zones. The requested resources are unavailable in the specified zone. Try a different resource type or select a different region or zone.
403 InvalidInstanceType.NotSupported The specified InstanceType is invalid.
403 Invalid.ZoneIds At least one of the specified ZoneIds are invalid. At least one of the specified ZoneIds is invalid.
403 Zone.NotOnSale The specified zone is not available for purchase. The requested resources are unavailable in the specified zone. Try a different instance type or select a different region or zone.
404 InvalidZoneId.NotFound The specified zoneId does not exist. The specified zone ID does not exist.
404 InvalidResourceGroup.NotFound The ResourceGroup provided does not exist in our records. The specified resource group does not exist.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.