All Products
Search
Document Center

ENS:CreateInstance

Last Updated:Mar 27, 2026

Creates an instance.

Operation description

  • up to 10 times per second per account.

  • We recommend that you increase the request time because instance creation is an asynchronous operation. If the return code of the API operation is 0, it indicates that the request is successful, but does not indicate that the instance is created. If the request is successful, an instance ID is returned. You can check whether the instance is created based on the instance ID.

  • InvalidUserData.NotInWhiteList operation restriction: You can create an instance only if you are in the whitelist in which members have the purchase permissions. Otherwise, an error is returned.

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

ens:CreateInstance

create

*Instance

acs:ens:*:{#accountId}:instance/*

None None

Request parameters

Parameter

Type

Required

Description

Example

InstanceType

string

Yes

The type of the instance.

For more information, see .

ens.se1.tiny

EnsRegionId

string

Yes

The region ID.

cn-hangzhou

Password

string

No

The password of the instance.

The password must be 8 to 30 characters in length and contain at least three of the following character types: uppercase letters, lowercase letters, digits, and special characters. Special characters include: ()`~!@#$%^&*-_+=|{}[]:;'<>,.?/

yourPassword:1

Period

string

Yes

The subscription period of the instance. Valid values: 1 to 9 and 12. Unit: months.

12

ImageId

string

No

The ID of the image file that you select when creating the instance.

yourImage ID

SystemDisk.Size

string

No

The size of the system disk. Unit: GiB. Valid values: 20 and 40. The value cannot be smaller than the size of the image and must be a multiple of 10 GiB.

40

Quantity

string

Yes

The number of instances.

1

DataDisk.1.Size

string

No

The capacity of the first data disk. Unit: GiB. The capacity is at least 20 GiB and is a multiple of 10 GiB.

50

InternetChargeType

string

No

This parameter is required if you create the instance for the first time. The existing billing method is used by default if you have created an instance. Valid values:

  • BandwidthByDay: Pay by daily peak bandwidth.

  • 95BandwidthByMonth: Pay by monthly 95th percentile bandwidth.

95BandwidthByMonth

AutoRenewPeriod

string

No

The auto-renewal period for the instance. This parameter is required when the AutoRenew parameter is set to True. Valid values: 1 to 12. Unit: months.

12

AutoRenew

string

No

Specifies whether to enable the auto-renewal feature. Valid values: True and False. Default value: False.

True

IpType

string

No

The type of the IP address. Valid values:

  • ipv4 (default)

  • ipv6

  • ipv4Andipv6

ipv4

KeyPairName

string

No

The name of the key pair. You can specify only one name.

TestKeyPairName

UserData

string

No

Custom data. The data starts with #!. The data can be at most 256 characters in length and 16 KB in size. Only custom scripts are supported and cannot be rendered by InstanceMetaData.

You can specify custom data. The data is encoded in Base64. The system does not encrypt your custom data when API requests are initiated. We recommend that you do not pass in confidential information such as passwords and private keys in plaintext. If you want to provide sensitive data such as passwords and private keys, encrypt the data and then encode it in Base64. The data is decrypted on the instance in the way it is encrypted.

For more information, see User data formats.

#!/bin/sh echo "Hello World. The time is now $(date -R)!" | tee /home/output.txt

VSwitchId

string

No

The ID of the vSwitch.

YourVSwitchId

PrivateIpAddress

string

No

The internal IP address. If this parameter is specified, you must specify the vSwitch ID. The vSwitch must be created first. Otherwise, an error is returned.

10.10.10.10

PaymentType

string

No

The billing method of the instance. Set the value to Subscription.

Subscription

InstanceName

string

No

The name of the instance. The name must conform to the following naming conventions:

  • The name must be 2 to 128 characters in length.

  • It must start with a letter but cannot start with http:// or https://.

  • The name can contain letters, digits, colons (:), underscores (_), periods (.), and hyphens (-).

If you do not specify this parameter, the instance ID is used as the instance name by default.

test:Instance_Name.1-2

HostName

string

No

The hostname of the Elastic Compute Service (ECS) instance. General naming rules: The hostname cannot start or end with a period (.) or hyphen (-). It cannot contain consecutive periods (.) or hyphens (-).

Naming rules for specific instances:

  • For Windows instances, the hostname must be 2 to 15 characters in length and cannot contain periods (.) or contain only digits. The hostname cannot contain periods (.) or contain only digits.

  • For instances that run one of other operating systems such as Linux, the hostname must be 2 to 64 characters in length. You can use periods (.) to separate the hostname into multiple segments. Each segment can contain letters, digits, and hyphens (-).

test-HostName

UniqueSuffix

boolean

No

Specifies whether to automatically append sequential suffixes to the hostnames specified by the HostName parameter and instance names specified by the InstanceName parameter. The sequential suffixes range from 001 to 999.

Examples: LocalHost001 and LocalHost002, and MyInstance001 and MyInstance002.

Default value: false.

false

PublicIpIdentification

boolean

No

Specifies whether a public IP address can be assigned to the specified instance. Valid values:

  • true

  • false

true

PasswordInherit

boolean

No

Specifies whether to use the preset password of the image. Valid values:

  • true: The password preset in the image is used, and the Password parameter must be null. For secure access, make sure that the selected image has a password configured.

  • false: does not use the password preset in the image.

false

Response elements

Element

Type

Description

Example

object

RequestId

string

The request ID.

4A431388-2D4B-46F4-A96B-D4E6BD0688C1

InstanceIds

object

InstanceId

array

The IDs of instances.

string

The list of instance IDs.

[i-7ecpqvkicnchxccozrp****,i-6ecpqvkicnchxccozrp****]

Code

integer

The return code. A value of 0 indicates that the request is successful.

Note

If you call this operation by using SDKs, the return value is of the integer type. If you call this operation by using common methods or HTTP requests, the return value is of the string type.

0

Examples

Success response

JSON format

{
  "RequestId": "4A431388-2D4B-46F4-A96B-D4E6BD0688C1",
  "InstanceIds": {
    "InstanceId": [
      "[i-7ecpqvkicnchxccozrp****,i-6ecpqvkicnchxccozrp****]"
    ]
  },
  "Code": 0
}

Error codes

HTTP status code

Error code

Error message

Description

400 StockNotEnough The specified instance type has insufficient resource.
400 InvalidUserData.NotInWhiteList The specified user is not authroized to perform this operation.
400 MissingParameter The input parameter that is mandatory for processing this request is not supplied.
400 InstanceIdNotFound The input parameter instancdId that is not found. The specified instance ID does not exist.
400 NoPermission Permission denied.
400 CallInterface Call Interface Happen Error. An error occurred when you call the operation.
400 InvalidParameter The input parameter is Invalid.
400 InvalidParameter.%s The specified field %s invalid. Please check it again.
400 InvalidDiskSize.ValueNotSupported The specified disk capacity is invalid. Specify another capacity and try again.
400 InvalidParameter.Bandwidth The specified parameter InternetChargeType is not valid.
400 InvalidParameter.Image The specified image does not support.
400 InvalidParameter.InstanceType The specified parameter InstanceType is not valid.
400 InvalidAccountStatus.NotEnoughBalance Your account does not have enough balance.
400 unsupported_Ipv6Feature This ensregion does not support creating instance of the IPv6 type. Select another type.
400 Forbidden.CreateInstance The user is not in the Goods whitelist of creating instance interface.
400 ENS_OperationUnsupported_KeyPairName The KeyPairNameis not available or image not support ssh key.
400 ENS_DependencyViolation_WindowsInstance The instance creating is window, only user password to login.
400 ENS_PASSWORDORKEYPAIRNAME_MODULE_NOT_CHOOSEN The required module pwd or keyPairName is not inputed
400 InvalidPrivateIpAddress Specified private IP address is not in the CIDR block of virtual switch.
400 InvalidVSwitchId.NotFound Specified virtual switch does not exist. The specified virtual switch ID does not exist.
400 InvalidPrivateIpAddress.Duplicated Specified private IP address is duplicated.
400 InvalidPasswordParam.Mismatch The input password should be null when passwordInherit is true.

See Error Codes for a complete list.

Release notes

See Release Notes for a complete list.