You can call this operation to create a launch template. A launch template removes the need to configure a large number of parameters every time you create an instance.
Description
Launch templates contain preset configurations used to create instances, such as the region, image ID, instance type, security group ID, and public bandwidth settings. If a specific parameter is not included in a launch template, you must manually specify the parameter when you use the launch template to create an instance.
After you create a launch template (CreateLaunchTemplate
), its version number is set to 1 by default. You can create multiple versions (CreateLaunchTemplateVersion
) based on this template. Version numbers start from 1 and increase in sequential
order. If you do not specify a template version number when you use a launch template
to create instances (RunInstances), the default version is used.
When you call this operation, take note of the following items:
- You can create up to 30 launch templates in each region. Each launch template can have up to 30 versions.
- Most parameters in launch templates are optional. When you create a launch template, ECS does not verify the existence or validity of specified parameter values. The validity of the parameter values are verified only when you create instances by using the launch template.
- If you set a specific parameter in a launch template, you cannot filter out this parameter
when you create instances (RunInstances) by using this template. For example, if you set the
HostName
parameter to LocalHost in a launch template and do not specify theHostName
parameter when you call theRunInstances
operation to create instances from the launch template, the instance hostname is stillLocalHost
. If you want to overwrite theLocalHost
value of HostName provided by the launch template, you can setHostName
to MyHost or another different value when you call theRunInstances
operation.
Debugging
Request parameters
Parameter | Type | Required | Example | Description |
---|---|---|---|---|
Action | String | Yes | CreateLaunchTemplate |
The operation that you want to perform. Set the value to CreateLaunchTemplate. |
LaunchTemplateName | String | Yes | testLaunchTemplateName |
The name of the launch template. The name must be 2 to 128 characters in length. It must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-). |
RegionId | String | Yes | cn-hangzhou |
The ID of the region. You can call the DescribeRegions operation to query the most recent region list. |
TemplateTag.N.Key | String | No | TestKey |
The key of tag N of the launch template. Valid values of N: 1 to 20. The tag key cannot be an empty string. It can be up to 128 characters in length and cannot start with acs: or aliyun. It cannot contain http:// or https://. |
TemplateTag.N.Value | String | No | TestValue |
The value of tag N of the launch template. Valid values of N: 1 to 20. The tag value can be an empty string. It can be up to 128 characters in length and cannot start with acs: or aliyun. It cannot contain http:// or https://. |
VersionDescription | String | No | testVersionDescription |
The description of the launch template version. The description must be 2 to 256 characters in length and cannot start with http:// or https://. |
ImageId | String | No | win2008r2_64_ent_sp1_en-us_40G_alibase_20170915.vhd |
The ID of the image. You can call the DescribeImages operation to query the available images. |
ImageOwnerAlias | String | No | system |
The source of the image. Valid values:
This parameter is empty by default, which indicates that the results matching the system, self, and others values are returned. |
PasswordInherit | Boolean | No | false |
Specifies whether to use the password preset in the image. Note To use the PasswordInherit parameter, you must leave the Password parameter empty
and ensure that the selected image has a password configured.
|
InstanceType | String | No | ecs.g5.large |
The instance type. For more information, see Instance families. Alternatively, you can call the DescribeInstanceTypes operation to query the most recent instance type list. |
SecurityGroupId | String | No | sg-bp15ed6xe1yxeycg**** |
The ID of the security group to which to assign the instance. Instances in the same security group can communicate with each other. One security group can contain a maximum of 1,000 instances. Note You cannot specify both the
SecurityGroupId and SecurityGroupIds.N parameters.
|
VpcId | String | No | vpc-bp12433upq1y5scen**** |
The ID of the VPC. |
VSwitchId | String | No | vsw-bp1s5fnvk4gn2tws0**** |
The ID of the vSwitch to which to connect the instance. This parameter is required if you specify the VpcId parameter. |
InstanceName | String | No | testInstanceName |
The name of the instance. The name must be 2 to 128 characters in length. It must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-). |
Description | String | No | testECSDescription |
The description of the instance. The description must be 2 to 256 characters in length and cannot start with http:// or https://. |
InternetMaxBandwidthIn | Integer | No | 10 |
The maximum inbound public bandwidth. Unit: Mbit/s. Valid values:
|
InternetMaxBandwidthOut | Integer | No | 10 |
The maximum outbound public bandwidth. Unit: Mbit/s. Valid values: 0 to 100. |
HostName | String | No | testHostName |
The hostname of the instance.
|
ZoneId | String | No | cn-hangzhou-g |
The ID of the zone. |
SystemDisk.Category | String | No | cloud_ssd |
The category of the system disk. Valid values:
For non-I/O optimized instances of the retired instance types, the default value is cloud. For other instances, the default value is cloud_efficiency. |
SystemDisk.Size | Integer | No | 40 |
The size of the system disk. Unit: GiB. Valid values: 20 to 500. The value of this parameter must be at least 20 and greater than or equal to the size of the image. |
SystemDisk.DiskName | String | No | testSystemDiskName |
The name of the system disk. The name must be 2 to 128 characters in length. It must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-). |
SystemDisk.Description | String | No | testSystemDiskDescription |
The description of the system disk. The description must be 2 to 256 characters in length and cannot start with http:// or https://. |
SystemDisk.PerformanceLevel | String | No | PL0 |
The performance level of the ESSD used as the system disk. Default value: PL0. Valid values:
For more information about ESSD performance levels, see ESSDs. |
SystemDisk.DeleteWithInstance | Boolean | No | true |
Specifies whether to release the system disk when the instance is released. Valid values:
Default value: true. |
DataDisk.N.Size | Integer | No | 2000 |
The size of data disk N. Valid values of N: 1 to 16. Unit: GiB. Valid values:
The value of this parameter must be greater than or equal to the size of the snapshot
specified by the |
DataDisk.N.SnapshotId | String | No | s-bp17441ohwka0yuh**** |
The ID of the snapshot used to create data disk N. Valid values of N: 1 to 16. When
the Use snapshots created after July 15, 2013. Otherwise, an error is returned and your request is rejected. |
DataDisk.N.Category | String | No | cloud_ssd |
The category of data disk N. Valid values:
For I/O optimized instances, the default value is cloud_efficiency. For non-I/O optimized instances, the default value is cloud. |
DataDisk.N.Encrypted | String | No | false |
Specifies whether to encrypt data disk N. |
DataDisk.N.DiskName | String | No | testDataDiskName |
The name of data disk N. The name must be 2 to 128 characters in length. It must start with a letter and cannot start with http:// or https://. The name can contain letters, digits, colons (:), underscores (_), and hyphens (-). |
DataDisk.N.Description | String | No | testDataDiskDescription |
The description of data disk N. The description must be 2 to 256 characters in length and cannot start with http:// or https://. |
DataDisk.N.DeleteWithInstance | Boolean | No | true |
Specifies whether to release data disk N when the instance is released. Valid values:
Default value: true. |
DataDisk.N.PerformanceLevel | String | No | PL1 |
The performance level of the ESSD used as data disk N. The N value must be the same
as that in DataDisk.N.Category when
For more information about ESSD performance levels, see ESSDs. |
IoOptimized | String | No | optimized |
Specifies whether the instance is I/O optimized. Valid values:
|
NetworkInterface.N.PrimaryIpAddress | String | No | 192.168.**. ** |
The primary private IP address of secondary elastic network interface (ENI) N. The value of N in |
NetworkInterface.N.VSwitchId | String | No | vsw-bp1s5fnvk4gn2tws0**** |
The ID of the vSwitch to which to connect secondary ENI N. The instance and secondary
ENI N must be located in the same zone of the same VPC, but they can be connected
to different vSwitches. The value of N in |
NetworkInterface.N.SecurityGroupId | String | No | sg-bp15ed6xe1yxeycg**** |
The ID of the security group to which to assign secondary ENI N. The security groups
of secondary ENI N and of the instance must belong to the same VPC. The value of N in Note You cannot specify both the
NetworkInterface.N.SecurityGroupId and NetworkInterface.N.SecurityGroupIds.N parameters.
|
NetworkInterface.N.NetworkInterfaceName | String | No | testEniName |
The name of secondary ENI N. The value of N in |
NetworkInterface.N.Description | String | No | testEniDescription |
The description of secondary ENI N. The description must be 2 to 256 characters in
length and cannot start with |
NetworkInterface.N.SecurityGroupIds.N | RepeatList | No | sg-bp67acfmxazb4p**** |
The ID of security group N to which to assign secondary ENI N. The security group
and secondary ENI N must belong to the same VPC. The valid values of N in Note You cannot specify both the
NetworkInterface.N.SecurityGroupId and NetworkInterface.N.SecurityGroupIds.N parameters.
|
InstanceChargeType | String | No | PrePaid |
The billing method of the instance. Valid values:
|
Period | Integer | No | 1 |
The subscription period of the instance. Unit: months. This parameter takes effect
and is required only when
|
InternetChargeType | String | No | PayByTraffic |
The billing method for network usage. Valid values:
Note When the pay-by-traffic billing method is used, the peak inbound and outbound bandwidth values are used as
traffic limits instead of guaranteed performance. When resources are insufficient,
these peak bandwidths cannot be guaranteed. If you want guaranteed bandwidths for
your instances, use the pay-by-bandwidth billing method.
|
EnableVmOsConfig | Boolean | No | false |
Specifies whether to enable the operating system configuration of the instance. Note This parameter will be removed in the future. We recommend that you use other parameters
to ensure future compatibility.
|
NetworkType | String | No | vpc |
The network type of the instance. Valid values:
|
UserData | String | No | ZWNobyBoZWxsbyBlY3Mh |
The user data of the instance. User data must be encoded in Base64. The maximum size of raw data is 16 KB. |
KeyPairName | String | No | testKeyPairName |
The name of the key pair.
|
RamRoleName | String | No | testRamRoleName |
The name of the instance RAM role. You can call the ListRoles operation provided by RAM to query the RAM roles that you have created. |
AutoReleaseTime | String | No | 2018-01-01T12:05:00Z |
The time scheduled for the instance to be automatically released. Specify the time in the ISO 8601 standard in the yyyy-MM-ddTHH:mm:ssZ format. The time must be in UTC.
|
SpotStrategy | String | No | NoSpot |
The preemption policy for the pay-as-you-go instance. This parameter takes effect
only when the
|
SpotPriceLimit | Float | No | 0.97 |
The maximum hourly price of the instance. This parameter takes effect only when |
SpotDuration | Integer | No | 1 |
The protection period of the preemptible instance. Unit: hours. Valid values: 0, 1, 2, 3, 4, 5, and 6.
Default value : 1. |
ResourceGroupId | String | No | rg-bp67acfmxazb4p**** |
The ID of the resource group to which to assign the instance, Elastic Block Storage (EBS) device, and ENI. |
TemplateResourceGroupId | String | No | rg-bp67acfmxazb4p**** |
The ID of the resource group to which to assign the launch template. |
SecurityEnhancementStrategy | String | No | Deactive |
Specifies whether to enable security hardening for the operating system. Valid values:
|
Tag.N.Key | String | No | TestKey |
The key of tag N of the instance, EBS device, or ENI. Valid values of N: 1 to 20. The tag key cannot be an empty string. It can be up to 64 characters in length and cannot start with acs: or aliyun. It cannot contain http:// or https://. |
Tag.N.Value | String | No | TestValue |
The value of tag N of the instance, EBS device, or ENI. Valid values of N: 1 to 20. The tag value can be an empty string. It can be up to 128 characters in length and cannot start with acs: or aliyun. It cannot contain http:// or https://. |
SecurityGroupIds.N | RepeatList | No | sg-bp15ed6xe1yxeycg7**** |
The ID of security group N to which to assign the instance. The valid values of N depend on the maximum number of security groups to which an instance can belong. For more information, see the "Security group limits" section of the Limits topic. Note You cannot specify both the
SecurityGroupId and SecurityGroupIds.N parameters.
|
PrivateIpAddress | String | No | 10.1.**. ** |
The private IP address of the instance. To assign a private IP address to a VPC-type ECS instance, make sure that the IP address
is an idle IP address within the CIDR block of the vSwitch specified by the |
Response parameters
Parameter | Type | Example | Description |
---|---|---|---|
LaunchTemplateId | String | lt-m5eiaupmvm2op9d**** |
The ID of the launch template. |
RequestId | String | 473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E |
The ID of the request. |
Examples
Sample requests
https://ecs.aliyuncs.com/?Action=CreateLaunchTemplate
&LaunchTemplateName=testLaunchTemplateName
&RegionId=cn-hangzhou
&TemplateTag.1.Key=TestKey
&TemplateTag.1.Value=TestValue
&VersionDescription=testVersionDescription
&ImageId=win2008r2_64_ent_sp1_en-us_40G_alibase_20170915.vhd
&InstanceType=ecs.g5.large
&SecurityGroupId=sg-bp15ed6xe1yxeycg****
&VpcId=vpc-bp12433upq1y5scen****
&VSwitchId=vsw-bp1s5fnvk4gn2tws03****
&InstanceName=testInstanceName
&Description=testECSDescription
&InternetMaxBandwidthIn=10
&InternetMaxBandwidthOut=10
&HostName=testHostName
&ZoneId=cn-hangzhou-g
&SystemDisk.Category=cloud_ssd
&SystemDisk.Size=40
&SystemDisk.DiskName=testSystemDiskName
&SystemDisk.Description=TestDisk
&DataDisk.1.Size=2000
&DataDisk.1.SnapshotId=s-bp17441ohwka0yuh****
&DataDisk.1.Category=cloud_ssd
&DataDisk.1.Encrypted=false
&DataDisk.1.DiskName=testDataDiskName
&DataDisk.1.Description=testDataDiskDescription
&DataDisk.1.DeleteWithInstance=true
&IoOptimized=optimized
&NetworkInterface.1.PrimaryIpAddress=192.168. **. **
&NetworkInterface.1.VSwitchId=vsw-bp1s5fnvk4gn2tws0****
&NetworkInterface.1.SecurityGroupId=sg-bp15ed6xe1yxeycg****
&NetworkInterface.1.NetworkInterfaceName=testEniName
&NetworkInterface.1.Description=testEniDescription
&PrivateIpAddress=10.1. **. **
&InstanceChargeType=PrePaid
&Period=1
&InternetChargeType=PayByTraffic
&NetworkType=vpc
&UserData=ZWNobyBoZWxsbyBlY3Mh
&RamRoleName=testRamRoleName
&AutoReleaseTime=2018-01-01T12:05:00Z
&SpotStrategy=NoSpot
&SpotPriceLimit=0.97
&SecurityEnhancementStrategy=Deactive
&Tag.1.Key=TestKey
&Tag.1.Value=TestValue
&<Common request parameters>
Sample success responses
XML
format
<CreateLaunchTemplateResponse>
<RequestId>473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E</RequestId>
<LaunchTemplateId>lt-m5eiaupmvm2op9d****</LaunchTemplateId>
</CreateLaunchTemplateResponse>
JSON
format
{
"RequestId": "473469C7-AA6F-4DC5-B3DB-A3DC0DE3C83E",
"LaunchTemplateId": "lt-m5eiaupmvm2op9d****"
}
Error codes
HTTP status code | Error code | Error message | Description |
---|---|---|---|
400 | InvalidRegion.NotExist | %s | The error message returned because the specified RegionId parameter does not exist. |
403 | LaunchTemplateLimitExceed | %s | The error message returned because the maximum number of launch templates has been reached. |
403 | LaunchTemplateName.Duplicated | %s | The error message returned because the specified LaunchTemplateName parameter already exists. |
400 | MissingParameter | %s | The error message returned because a required parameter is not specified. |
400 | InvalidParameter | %s | The error message returned because a specified parameter is invalid. |
400 | InvalidLaunchTemplateName.Malformed | The specified parameter LaunchTemplateName is not valid. | The error message returned because the specified LaunchTemplateName parameter is invalid. |
400 | InvalidDescription.Malformed | The specified parameter "VersionDescription" is not valid. | The error message returned because the specified VersionDescription parameter is invalid. |
400 | InvalidUserData.SizeExceeded | %s | The error message returned because the size of the specified user data exceeds the upper limit. |
400 | InvalidUserData.Base64FormatInvalid | %s | The error message returned because the specified UserData parameter is invalid. |
400 | Duplicate.TagKey | The Tag.N.Key contain duplicate key. | The error message returned because the specified tag key already exists. Tag keys must be unique. |
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 | InvalidTagValue.Malformed | The specified Tag.n.Value is not valid. | The error message returned because the specified Tag.N.Value parameter is invalid. |
403 | QuotaExceed.Tags | %s | The error message returned because the maximum number of tags has been reached. |
404 | InvalidResourceGroup.NotFound | The ResourceGroup provided does not exist in our records. | The error message returned because the specified ResourceGroupId parameter does not exist. |
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. |
400 | InvalidHostName.Malformed | The specified parameter "HostName" is not valid. | The error message returned because the specified HostName parameter is invalid. |
For a list of error codes, visit the API Error Center.