All Products
Search
Document Center

ENS:CreateInstance

Last Updated:Jul 26, 2024

Creates an instance.

Operation description

  • You can call this operation 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.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer.

Authorization information

The following table shows the authorization information corresponding to the API. The authorization information can be used in the Action policy element to grant a RAM user or RAM role the permissions to call this API operation. Description:

  • Operation: the value that you can use in the Action element to specify the operation on a resource.
  • Access level: the access level of each operation. The levels are read, write, and list.
  • Resource type: the type of the resource on which you can authorize the RAM user or the RAM role to perform the operation. Take note of the following items:
    • The required resource types are displayed in bold characters.
    • If the permissions cannot be granted at the resource level, All Resources is used in the Resource type column of the operation.
  • Condition Key: the condition key that is defined by the cloud service.
  • Associated operation: other operations that the RAM user or the RAM role must have permissions to perform to complete the operation. To complete the operation, the RAM user or the RAM role must have the permissions to perform the associated operations.
OperationAccess levelResource typeCondition keyAssociated operation
ens:CreateInstancecreate
  • Instance
    acs:ens:*:{#accountId}:instance/*
    none
none

Request parameters

ParameterTypeRequiredDescriptionExample
InstanceTypestringYes

The type of the instance.

For more information, see .

ens.se1.tiny
EnsRegionIdstringYes

The region ID.

cn-hangzhou
PasswordstringNo

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
PeriodstringYes

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

12
ImageIdstringNo

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

yourImage ID
SystemDisk.SizestringNo

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
QuantitystringYes

The number of instances.

1
DataDisk.1.SizestringNo

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

50
InternetChargeTypestringNo

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
AutoRenewPeriodstringNo

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
AutoRenewstringNo

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

True
IpTypestringNo

The type of IP address. Valid values:

  • ipv4: IPv4. This is the default value.
  • ipv6: IPv6.
  • ipv4Andipv6: IPv4 and IPv6.
ipv4
KeyPairNamestringNo

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

TestKeyPairName
UserDatastringNo

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
VSwitchIdstringNo

The ID of the vSwitch.

YourVSwitchId
PrivateIpAddressstringNo

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
PaymentTypestringNo

The billing method of the instance. The value is set to Subscription.

Subscription
InstanceNamestringNo

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
HostNamestringNo

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
UniqueSuffixbooleanNo

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 numbers in the suffix range from 001 to 999.

Examples: LocalHost001 and LocalHost002, and MyInstance001 and MyInstance002.

Default value: false.

false
PublicIpIdentificationbooleanNo

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

  • true
  • false
true
PasswordInheritbooleanNo

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 parameters

ParameterTypeDescriptionExample
object
RequestIdstring

The request ID.

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

The IDs of instances.

string

The list of instance IDs.

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

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

Sample success responses

JSONformat

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

Error codes

HTTP status codeError codeError messageDescription
400StockNotEnoughThe specified instance type has insufficient resource.-
400InvalidUserData.NotInWhiteListThe specified user is not authroized to perform this operation.-
400MissingParameterThe input parameter that is mandatory for processing this request is not supplied.-
400InstanceIdNotFoundThe input parameter instancdId that is not found.The specified instance ID does not exist.
400NoPermissionPermission denied.-
400CallInterfaceCall Interface Happen Error.An error occurred when you call the operation.
400InvalidParameterThe input parameter is Invalid.-
400StockNotEnoughThe specified configuration is unavailable. Reconfigure and try again.-
400InvalidParameter.%sThe specified field %s invalid. Please check it again.-
400InvalidParameterThe errorMessage is %s. Please check it again.-
400StockNotEnoughThe specified EnsRegionId is unavailable. Reconfigure and try again.-
400StockNotEnoughThe specified InstanceSpec is unavailable. Reconfigure and try again.-
400InvalidDiskSize.ValueNotSupportedThe specified disk capacity is invalid. Specify another capacity and try again.-
400InvalidParameter.BandwidthThe specified parameter InternetChargeType is not valid.-
400StockNotEnoughThe specified node has insufficient resource.-
400InvalidParameter.ImageThe specified image does not support.-
400StockNotEnoughYou have reached the purchase default limit.-
400InvalidParameter.InstanceTypeThe specified parameter InstanceType is not valid.-
400InvalidAccountStatus.NotEnoughBalanceYour account does not have enough balance.-
400unsupported_Ipv6FeatureThis ensregion does not support creating instance of the IPv6 type. Select another type.-
400Forbidden.CreateInstanceThe user is not in the Goods whitelist of creating instance interface.-
400ENS_OperationUnsupported_KeyPairNameThe KeyPairNameis not available or image not support ssh key.-
400ENS_DependencyViolation_WindowsInstanceThe instance creating is window, only user password to login.-
400ENS_PASSWORDORKEYPAIRNAME_MODULE_NOT_CHOOSENThe required module pwd or keyPairName is not inputed-
400MissingParameterThe input parameter %s that is mandatory for processing this request is not supplied.-
400InvalidPrivateIpAddressSpecified private IP address is not in the CIDR block of virtual switch.-
400InvalidVSwitchId.NotFoundSpecified virtual switch does not exist.-
400InvalidPrivateIpAddress.DuplicatedSpecified private IP address is duplicated.-
400InvalidPasswordParam.MismatchThe input password should be null when passwordInherit is true.-

For a list of error codes, visit the Service error codes.

Change history

Change timeSummary of changesOperation
2023-10-12The Error code has changedView Change Details
2023-03-03The Error code has changedView Change Details