createLaunchTemplate

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 Launch an instance from a launch template in the Amazon Elastic Compute Cloud User Guide.

If you want to clone an existing launch template as the basis for creating a new launch template, you can 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 Elastic Compute Cloud User Guide.

Samples

import aws.sdk.kotlin.services.ec2.model.LaunchTemplateInstanceNetworkInterfaceSpecificationRequest
import aws.sdk.kotlin.services.ec2.model.LaunchTemplateTagSpecificationRequest
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
}