createLaunchTemplate
inline suspend fun Ec2Client.createLaunchTemplate(crossinline block: CreateLaunchTemplateRequest.Builder.() -> Unit): CreateLaunchTemplateResponse
Creates a launch template.
A launch template contains the parameters to launch an instance. When you launch an instance using RunInstances, you can specify a launch template instead of providing the launch parameters in the request. For more information, see Store instance launch parameters in Amazon EC2 launch templates in the Amazon EC2 User Guide.
To clone an existing launch template as the basis for a new launch template, use the Amazon EC2 console. The API, SDKs, and CLI do not support cloning a template. For more information, see Create a launch template from an existing launch template in the Amazon EC2 User Guide.
Samples
import aws.sdk.kotlin.services.ec2.model.InstanceType
import aws.sdk.kotlin.services.ec2.model.LaunchTemplateInstanceNetworkInterfaceSpecificationRequest
import aws.sdk.kotlin.services.ec2.model.LaunchTemplateTagSpecificationRequest
import aws.sdk.kotlin.services.ec2.model.RequestLaunchTemplateData
import aws.sdk.kotlin.services.ec2.model.ResourceType
import aws.sdk.kotlin.services.ec2.model.Tag
fun main() {
//sampleStart
// This example creates a launch template that specifies the subnet in which to launch the instance,
// assigns a public IP address and an IPv6 address to the instance, and creates a tag for the instance.
val resp = ec2Client.createLaunchTemplate {
launchTemplateName = "my-template"
versionDescription = "WebVersion1"
launchTemplateData = RequestLaunchTemplateData {
networkInterfaces = listOf<LaunchTemplateInstanceNetworkInterfaceSpecificationRequest>(
LaunchTemplateInstanceNetworkInterfaceSpecificationRequest {
associatePublicIpAddress = true
deviceIndex = 0
ipv6AddressCount = 1
subnetId = "subnet-7b16de0c"
}
)
imageId = "ami-8c1be5f6"
instanceType = InstanceType.fromValue("t2.small")
tagSpecifications = listOf<LaunchTemplateTagSpecificationRequest>(
LaunchTemplateTagSpecificationRequest {
resourceType = ResourceType.fromValue("instance")
tags = listOf<Tag>(
Tag {
key = "Name"
value = "webserver"
}
)
}
)
}
}
//sampleEnd
}