阅读586 返回首页    go 阿里云 go 技术社区[云栖]


创建实例__实例相关接口_API 参考_云服务器 ECS-阿里云

描述

创建实例需要通过实名认证。没有通过实名认证的可以前往 阿里云官网 中的用户中心—>会员信息中进行实名认证。

根据传入参数创建弹性计算实例。

  • 在创建实例时,必须要选择镜像,用来确定新创建实例的系统盘配置。镜像包含操作系统以及应用软件配置,基于镜像创建实例后,实例的系统盘即为此镜像的完全克隆。

  • 一个实例创建时必须指定加入一个安全组。安全组需要预先创建,可通过创建安全组接口创建,可以在新创建实例时指定,也可通过 修改实例属性 的接口来完成实例所属安全组变更。在同一个安全组内的实例内网可以相互访问,但不同安全组之间默认有防火墙隔离,不可相互访问,但可通过安全组授权(通过授权安全组权限接口实现)来设置此安全组的防火墙权限。同一个安全组内的实例数量不能超过1000个,若组内实例数量超出限制,创建实例时若指定该安全组,会提示失败。

  • 在创建实例时,如果参数InternetChargeType的值设置为PayByBandwidth(按固定带宽付费),则InternetMaxBandwidthOut的设置值即为所选的固定带宽值;如果参数InternetChargeType的值设置为PayByTraffic(按流量付费),则InternetMaxBandwidthOut只是一个带宽的上限设置,计费以发生的网络流量为依据。设置InternetChargeType和InternetMaxBandwidthOut时,应仔细核算可能发生的带宽费用。

  • InternetMaxBandwidthIn的值在任何情况下都与计费无关,实例的入数据流量是免费的。

  • 创建实例时,可以选择是否为IO优化实例(IoOptimized)。

  • 实例创建时,系统会根据用户所指定镜像为实例分配一个相应大小的系统盘,系统盘容量=Max{40,ImageSize};也可以指定系统盘的容量SystemDisk.size参数,该参数必须大于等于max{40,ImageSize};同时,可以指定系统盘的种类:普通云盘(cloud)、高效云盘(cloud_efficiency)、SSD云盘(cloud_ssd)、本地 SSD 盘(ephemeral_ssd)。

  • 当实例选择为IO优化实例时,系统盘只能选择高效云盘(cloud_efficiency)及SSD云盘(cloud_ssd)

  • ECS不支持单独创建或者添加本地SSD盘,因此本地SSD盘必须在创建实例时指定,实例创建完成后不能再添加。各个实例规格对不同磁盘种类大小的限制见 实例资源规格对照表

  • 单块普通云盘(cloud)容量最大不能超过2000GB,单块高效云盘(cloud_efficiency)容量最大不超过32TB(32768GB),单块SSD云盘(cloud_ssd)容量最大不能超过32TB(32768GB),单块本地 SSD 盘(ephemeral_ssd)容量最大不能超过 800GB。

  • 随实例创建的系统盘,其Portable属性为false,即不支持卸载和挂载操作。系统盘随实例的释放而释放,所以系统盘的DeleteWithInstance的属性为True。

  • 随实例创建的类型为普通云盘(cloud)、高效云盘(cloud_efficiency)或SSD云盘(cloud_ssd)的数据盘,其Portable属性为true,即支持卸载和挂载操作。如果数据盘随实例的释放而释放,则DeleteWithInstance的属性的默认值为True;反之,如果数据盘不随实例的释放而释放,则DeleteWithInstance的属性的默认值为False

  • 随实例创建的本地 SSD 盘(ephemeral_ssd),其 Portable 属性为 false,即不支持卸载和挂载操作。本地 SSD 盘随实例的释放而释放,所以其 DeleteWithInstance 的属性为 True。

  • 一个实例最多添加4块数据盘;数据盘选择本地 SSD 盘时,系统盘必须为本地 SSD 盘,同时一个实例的本地 SSD 盘总容量不超过 1TB(1024GB,不包括系统盘)。

  • 选择了本地SSD盘的实例,一旦创建后,不能修改实例规格。

  • 实例内存为512M时不能使用 Windows 操作系统;内存为 4G以上时不能使用 32位操作系统。

  • 当系统盘是普通云盘(cloud)、高效云盘(cloud_efficiency)或SSD云盘(cloud_ssd)时,数据盘不能是ephemeral_ssd。

  • 专有网络类型实例只能在创建时指定,这类实例必须且只能属于一个虚拟交换机。

  • 指定VSwitchId创建实例时,SecurityGroupId和VSwitchId要属于同一个专有网络。

  • VSwitchId和PrivateIpAddress同时指定时,PrivateIpAddress要包含在虚拟交换机的CidrBlock之内。

  • PrivateIpAddress依赖于VSwitchId,不能单独指定PrivateIpAddress。

  • 若实例付费类型为预付费的包年包月实例(PrePaid),则在执行付款时默认会使用该账号下可用的优惠券(0折账号除外)

  • 创建完成后,实例为 Stopped 状态

  • 在阿里云CLI及SDK中使用该API时,部分带”.”号的入参需要去掉”.”号使用,包括:SystemDisk.Category、SystemDisk.Size、SystemDisk.Description、DataDisk.n.Size、DataDisk.n.Category、DataDisk.n.SnapshotId、DataDisk.n.DiskName、DataDisk.n.Description、DataDisk.n.Device、DataDisk.n.DeleteWithInstance。如:在阿里云CLI及SDK中使用SystemDiskCategory来表示SystemDisk.Category入参

请求参数

名称 类型 是否必须 描述
Action String 操作接口名,系统规定参数,取值:CreateInstance
RegionId String 实例所属的Region ID
ZoneId String 实例所属的可用区编号,空表示由系统选择,默认值:空。
ImageId String 镜像文件ID,表示启动实例时选择的镜像资源
InstanceType String 实例的资源规则。取值参见附表实例资源规格对照表,也可以调用查询实例资源规格列表接口获得最新的规格表。
SecurityGroupId String 指定新创建实例所属于的安全组代码,同一个安全组内的实例之间可以互相访问。若不指定,则会将创建的实例加入到默认安全组中。如果默认安全组还不存在,或者默认安全组的实例数量已经超过了上限,则自动新建一个。
InstanceName String 实例的显示名称,[2,128]英文或中文字符,必须以大小字母或中文开头,可包含数字,“.”,“_”或“-”。 实例名称会显示在控制台。 如果没有指定该参数,默认值为实例的InstanceId 不能以https:// 和https:// 开头。
Description String 实例的描述,[2,256]个字符,实例描述会显示在控制台。不填则为空,默认为空。不能以https:// 和https:// 开头。
InternetChargeType String 网络计费类型,按流量计费还是按固定带宽计费。
可选值:
  • PayByBandwidth
  • PayByTraffic
如用户不指定,默认是PayByBandwidth。
InternetMaxBandwidthIn String 公网入带宽最大值,单位为Mbps(Mega bit per second),取值范围:[1,200]
如果客户不指定,AliyunAPI将自动将入带宽设置成200Mbps。
InternetMaxBandwidthOut String 公网出带宽最大值,单位为 Mbps(Mega bit per second),取值范围:
按带宽计费:[0, 100]。如果客户不指定,API 将自动将出带宽设置成 0Mbps。
按流量计费:[1, 100]。如果客户不指定,会报错。
如果需要可以通过阿里云工单系统申请将带宽范围设置成 1 ~ 200Mbps。
HostName String 表示云服务器的主机名,最少2字符,“.”和“-”是不能作为hostname的首尾字符,不能连续使用。 Windows平台最长为15字符,允许字母(不限制大小写)、数字和“-”组成,不支持点号(”.”),不能全是数字。
其他(Linux等)平台最长为30字符,允许支持多个点号,点之间为一段,每段允许字母(不限制大小写)、数字和“-”组成。
Password String 实例的密码。8-30个字符,必须同时包含三项(大、小写字母,数字和特殊符号)。支持以下特殊字符:( ) ` ~ ! @ # $ % ^ & * - + = | { } [ ] : ; ‘ < > , . ? /
如果传入Password参数,请务必使用HTTPS协议调用API以避免可能发生的密码泄露。
IoOptimized String IO优化。
可选值:
  • none:非 IO 优化
  • optimized:IO 优化
默认值:none。
SystemDisk.Category String 系统盘的磁盘种类
可选值:
  • cloud – 普通云盘
  • cloud_efficiency – 高效云盘
  • cloud_ssd – SSD云盘
  • ephemeral_ssd - 本地 SSD 盘
默认值:cloud
SystemDisk.Size Integer 系统盘大小,以GB为单位,取值范围为:
  • cloud – 40~500
  • cloud_efficiency – 40~500
  • cloud_ssd – 40~500
  • ephemeral_ssd - 40~500
默认值:size=max{40,ImageSize}
指定该参数后,size必须大于等于max{40, ImageSize}。
SystemDisk.DiskName String 系统盘名称,不填则为空,默认值为空,[2,128]英文或中文字符,必须以大小字母或中文开头,可包含数字,”_”或”-”,磁盘名称会展示在控制台。不能以https:// 和https:// 开头。
SystemDisk.Description String 系统盘描述,不填则为空,默认值为空,[2,256]个字符,实例描述会显示在控制台。不填则为空,默认为空。不能以https:// 和https:// 开头。
DataDisk.n.Size Integer 数据盘n的磁盘大小(n从1开始编号)。 以GB为单位,取值范围为:
  • cloud:5 ~ 2000
  • cloud_efficiency:20 ~ 32768
  • cloud_ssd:20 ~ 32768
  • ephemeral_ssd:5 ~ 800
指定该参数后,Size大小必须 ≥ 指定快照SnapshotId的大小。
DataDisk.n.Category String 数据盘n的磁盘种类
可选值:
  • cloud – 普通云盘
  • cloud_efficiency – 高效云盘
  • cloud_ssd – SSD云盘
  • ephemeral_ssd - 本地 SSD 盘
默认值:cloud
DataDisk.n.SnapshotId String 创建数据盘使用的快照
指定该参数后DataDisk.n.Size会被忽略,实际创建的磁盘大小为指定快照的大小。若该快照创建于2013年7月15日(含)之前,该次调用会被拒绝,Response中返回InvalidSnapshot.TooOld
DataDisk.n.DiskName String 数据盘名称,不填则为空,默认值为空,[2,128]英文或中文字符,必须以大小字母或中文开头,可包含数字,”_”或”-”,磁盘名称会展示在控制台。不能以https:// 和https:// 开头。
DataDisk.n.Description String 数据盘描述,不填则为空,默认值为空,[2,256]个字符,磁盘描述会展示在控制台。不能以https:// 和https:// 开头。
DataDisk.n.Device String 空表示由系统默认分配,/dev/xvdb 开始到 /dev/xvdz
默认值:空
DataDisk.n.DeleteWithInstance String 表示数据盘是否随实例释放。
  • true表示实例释放时,这块磁盘随实例一起释放
  • false表示实例释放时,这块磁盘保留不释放
默认值:true
这个参数只对独立云磁盘即DataDisk.n.Category=cloud,cloud_efficiency和cloud_ssd 时有效,否则会报错。
VSwitchId String 如果是创建VPC类型的实例,需要指定虚拟交换机的ID
PrivateIpAddress 实例私网IP地址,不能单独指定。
InstanceChargeType String 实例的付费方式。
  • PrePaid:预付费,即包年包月,选择该类付费方式的用户必须确认自己的账号支持余额支付/信用支付,否则将返回“无效的支付方式”的错误提示
  • PostPaid:后付费,即按量付费
默认为 PostPaid,即按量付费。
Period Integer 购买资源的时长,单位是月。
当 InstanceChargeType 为 PrePaid 时,才生效且为必选。
取值范围为:
  • 1 - 9
  • 12
  • 24
  • 36
AutoRenew String 是否要自动续费,当 InstanceChargeType 为 PrePaid 时才生效。
取值范围:
  • True,代表要自动续费
  • False,代表不要自动续费
默认值:False。
AutoRenewPeriod Integer 每次自动续费的时长,当AutoRenew为True时为必填:
  • 1
  • 2
  • 3
  • 6
  • 12
ClientToken String 用于保证请求的幂等性。由客户端生成该参数值,要保证在不同请求间唯一,最大不值过64个ASCII字符。
具体参见附录:如何保证幂等性

返回参数

名称 类型 描述
InstanceId String 实例ID,由系统生成,全局唯一。是访问实例的唯一标识

错误码

错误代码 描述 Http状态码 语义
InvalidRegionId.NotFound The RegionId provided does not exist in our records. 404 指定的RegionId不存在
MissingParameter The input parameter “RegionId” that is mandatory for processing this request is not supplied. 400 缺少RegionId值(实际情况也可能是该用户无权使用此Region)
InvalidInstanceType.ValueUnauthorized The specified InstanceType is not authorized. 400 指定的InstanceType未授权使用
InvalidSystemDiskSize.LessThanImageSize The specified parameter“SystemDisk.Size”is less than the image size 404 指定的 SystemDiskSize 小于镜像的大小
InvalidSystemDiskSize.MoreThanMaxSize The specified parameter “SystemDisk.Size” is more than the max size 404 指定的 SystemDiskSize 大于最大容量上限
InvalidSystemDiskSize.LessThanMinimumSize The specified parameter”SystemDisk.Size” is less than the minimum size 404 指定的 SystemDiskSize 小于最小容量
InvalidZoneId.NotFound The ZoneId provided does not exist in our records. 404 指定的ZoneId不存在(实际情况也可能是该用户无权使用此Zone)
MissingParameter The input parameter “ImageId” that is mandatory for processing this request is not supplied. 400 缺少ImageId值
InvalidInstanceType.ValueNotSupported The specified InstanceType beyond the permitted range. 400 指定的InstanceType不合法(超出可选范围)
MissingParameter The input parameter “InstanceType” that is mandatory for processing this request is not supplied. 400 缺少InstanceType值
InvalidSecurityGroupId.NotFound The SecurityGroupId provided does not exist in our records. 404 指定的SecurityGroupId不存在(实际情况也可能是该用户无权使用此SecurityGroup)
MissingParameter The input parameter “SecurityGroupId” that is mandatory for processing this request is not supplied. 400 缺少SecurityGroupId值
InvalidDescription.Malformed The specified parameter “Description” is not valid. 400 指定的Description格式不合法
InvalidInternetChargeType.ValueNotSupported The specified InternetChargeType is not valid. 400 指定的InternetChargeType不存在
InvalidParameter The specified parameter “InternetMaxBandwidthIn” is not valid. 400 指定的InternetMaxBandwidthIn不合法(不是数字或超出范围)
InvalidParameter The specified parameter “InternetMaxBandwidthOut” is not valid. 400 指定的InternetMaxBandwidthOut不合法(不是数字或超出范围)
InvalidHostName.Malformed The specified parameter “HostName” is not valid. 400 指定的HostName格式不合法
InvalidPassword.Malformed The specified parameter “Password” is not valid. 400 指定的Password格式不合法
InvalidSystemDiskCategory.ValueNotSupported The specified parameter “SystemDisk.Category” is not valid. 400 指定的SystemDisk.Category不合法
InvalidDiskName.Malformed The specified parameter “SyatemDisk.DiskName or DataDisk.n.DiskName” is not valid. 400 指定的SyatemDisk.DiskName或DataDisk.n.DiskName不合法
InvalidDiskDescription.Malformed The specified parameter “SyatemDisk.DiskDescription” or “DataDisk.n.Description” is not valid. 400 指定的SyatemDisk.DiskDescription或DataDisk.n.Description不合法
InvalidParameter The specified parameter “DataDisk.n.Size” is not valid. 400 指定的DataDisk.n.Size不合法(不是数字)
OperationDenied The specified parameter “VlanId” is not valid or vlan has not enough IP address. 400 指定的 VlanId 不合法
InvalidDataDiskSize.ValueNotSupported The specified DataDisk.n.Size beyond the permitted range, or the capacity of snapshot exceeds the size limit of the specified disk category. 400 指定的DataDisk.n.Size不合法(超出范围)
InvalidDataDiskCategory.ValueNotSupported The specified parameter “DataDisk.n.Category” is not valid. 400 指定的DataDisk.n.Category不合法
InvalidDataDiskSnapshotId.NotFound The specified parameter “DataDisk.n.SnapshotId” is not valid. 404 指定的DataDisk.n.SnapshotId没找到
InvalidDataDevice.Malformed The specified parameter “DataDisk.n.Device” is not valid. 400 指定的DataDisk.n.Device不合法
InvalidParameter.Conflict The specified image does not support the specified instance type. 400 指定的InstanceType上不允许使用该指定的镜像
InvalidSnapshotId.BasedSnapshotTooOld The specified snapshot is created before 2013-07-15. 400 使用了2013-07-15之前创建的Snapshot
QuotaExceed.AfterpayInstance Living afterpay instances quota exceeded. 400 用户的按量付费Instance个数达到上限
ImageNotSubscribed The specified image has not be subscribed. 403 没有订阅镜像市场的镜像
OperationDenied The specified Image is disabled or is deleted. 403 镜像不可用或者不存在
InvalidSystemDiskCategory.ValueUnauthorized The disk category is not authorized. 403 磁盘种类未被授权使用
InvalidParameter.Mismatch The data disk must be cloud disk when system disk category is cloud. 403 系统盘是云磁盘则数据盘必须是云磁盘
InvalidSnapshotId.NotReady The specified snapshot has not completed yet. 403 快照没有完成
OperationDenied The specified snapshot is not allowed to create disk. 403 特定磁盘的快照不能创建磁盘或者快照不能创建磁盘
InstanceDiskCategoryLimitExceed The total size of specified disk category in an instance exceeds. 403 指定的磁盘种类超过了单实例的最大容量
InvalidDevice.InUse The specified device has been occupied. 403 挂载点已被占用
ImageRemovedInMarket The specified market image is not available, Or the specified user defined image includes product code because it is based on an image subscribed from marketplace, and that image in marketplace includeing exact the same product code has been removed. 403 镜像市场的镜像已下架,或者自定义镜像中包含的product code对应的镜像市场镜像已经下架
InvalidClusterId.NotFound The ClusterId provided does not exist in our records. 404 指定的 ClusterId 不存在
OperationDenied The creation of Instance to the specified Zone is not allowed. 403 该可用区无权创建实例或者Zone和Region不匹配
CategoryNotSupported The specified zone does not offer the specified disk category. 403 该可用区无权创建指定种类的磁盘
OperationDenied The specified Zone or cluster does not offer the specified disk category or the speicified zone and cluster do not match. 403 zone或者cluster不支持该磁盘种类,或者zone和cluster不匹配
InvalidInstanceName.Malformed The specified parameter “InstanceName” is not valid. 400 指定的InstanceName格式不合法
InvalidInstanceDescription.Malformed The specified parameter “Description” is not valid. 400 指定的Instance Description不合法
OperationDenied The specified Image is disabled or is deleted. 404 指定的镜像找不到
OperationDenied The resource is out of usage. 403 zone或者Cluster的库存不够了
InternalError The request processing has failed due to some unknown error. 500 该用户没有zone可用
OperationDenied The specified region is in resource control, please try later. 403 Region暂时停售按量实例
InvalidParameter.Conflict The speicified region and cluster do not match. 400 Region和Cluster不匹配
SecurityGroupInstanceLimitExceed Exceeding the allowed amount of instances of a security group. 403 该SecurityGroup内的Instance数量已经达到上限
RegionUnauthorized There is no authority to create instance in the specified region. 403 用户无权使用该Region
CategoryNotSupported The specified Zone or cluster does not offer the specified disk category. 403 zone或者cluster不支持磁盘种类
InvalidSnapshotId.NotDataDiskSnapshot The specified snapshot is system disk snapshot. 403 系统盘快照不能创建数据盘
OperationDenied The capacity of snapshot exceeds the size limit of the specified disk category or the specified category is not authorizied. 403 指定的DataDisk.n.Size不合法(超出范围)或者磁盘种类未被授权使用
CategoryNotSupported The specified cluster does not offer the specified disk category. 403 cluster不支持磁盘种类
InvalidDiskCategory.Mismatch The specified disk categories’ combination is not supported.. 403 所选磁盘类型的组合不支持
QuotaExceed.PortableCloudDisk The quota of portable cloud disk exceeds. 403 可挂载的云磁盘数量已经达到上限(最多四块)
DeleteWithInstance.Conflict The specified disk is not a portable disk and cannot be set to DeleteWithInstance attribute. 403 该磁盘不支持挂载与卸载
IoOptimized.NotSupported The specified image is not support IoOptimized Instance. 403 指定的镜像ID不支持 IO 优化实例
OperationDenied Another Instance has been creating 403 同步请求,创建 ECS 的数量超过一个
IoOptimized.NotSupported The specified instancetype is not support IoOptimized instance 403 实例类型不支持 IO 优化实例
OperationDenied The specified zone does not support creating instance. 403 所选的可用区不支持创建IO优化型实例
InvalidDiskCategory.NotSupported The specified disk category is not support the specified instance type. 403 所选磁盘种类不能用于所选实例类型
InstanceDiskCategoryLimitExceed The specified DataDisk.n.Size beyond the permitted range, or the capacity of snapshot exceeds the size limit of the specified disk category. 400 指定的 DataDisk.n.Size 不合法(超出范围)
QuotaExceed.BuyImage The specified image is from the image market,You have not bought it or your quota has been exceeded. 403 指定的镜像来自镜像市场,您没有购买或者该镜像在次地域的配额已用完
TotalDiskSizeLimitExceed The sum of the specified DataDisk.n.Size beyond the permitted range. 403 指定的磁盘的总容量超过了单台实例可挂载磁盘总容量的上限
InvalidInstanceChargeType.NotFound The InstanceChargeType does not exist in our records 404 指定的 InstanceChargeType 不存在
DependencyViolation.Image The specified imageid is not supported to create iooptimized instance 400 指定的镜像 ID 不支持创建 IO 优化实例
InvalidPeriod The specified period is not valid 400 指定的 period 参数格式不合法(不是数字或超出范围)
InstanceTypeNotSupported The specified zone does not offer the specified instancetype. 403 该可用区不支持创建指定的实例规格
DependencyViolation.IoOptimized The specified instancetype must be IoOptimized instance 404 指定的实例规格必须是 I/O 优化实例
InvalidPeriod The specified period is not valid 400 指定的 period 参数格式不合法(不是数字或超出范围)
InstanceDiskNumber.LimitExceed The total number of specified disk in an instance exceeds. 403 镜像中包含的数据盘和数据盘参数合并后,数据盘的总数超出限制
InvalidAutoRenewPeriod.ValueNotSupported auto renew period value is not supported 400 指定的 AutoRenew period 参数格式不合法(不是数字或超出范围)

示例

请求示例

  1. https://ecs.aliyuncs.com/?Action=CreateInstance
  2. &RegionId=cn-hangzhou
  3. &ImageId=_32_23c472_20120822172155_aliguest.vhd
  4. &SecurityGroupId=sg-c0003e8b9
  5. &HostName=Bctest01
  6. &InstanceType=ecs.t1.small
  7. &<公共请求参数>

返回示例

XML格式

  1. <CreateInstanceResponse>
  2. <RequestId>04F0F334-1335-436C-A1D7-6C044FE73368</RequestId>
  3. <InstanceId>i-instance1</InstanceId>
  4. </CreateInstanceResponse>

JSON格式

  1. {
  2. "RequestId": "04F0F334-1335-436C-A1D7-6C044FE73368",
  3. "InstanceId": "i-instance1"
  4. }

最后更新:2016-11-23 16:03:50

  上一篇:go ECS API 发生子账号访问主账号资源时的鉴权规则__借助 RAM 实现子账号对主账号的 ECS 资源访问_API 参考_云服务器 ECS-阿里云
  下一篇:go 启动实例__实例相关接口_API 参考_云服务器 ECS-阿里云