aws-cdk-lib.aws_ec2.LaunchTemplateProps

interface LaunchTemplateProps

LanguageType name
.NETAmazon.CDK.AWS.EC2.LaunchTemplateProps
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awsec2#LaunchTemplateProps
Javasoftware.amazon.awscdk.services.ec2.LaunchTemplateProps
Pythonaws_cdk.aws_ec2.LaunchTemplateProps
TypeScript (source)aws-cdk-lib » aws_ec2 » LaunchTemplateProps

Properties of a LaunchTemplate.

Example

const sg1 = new ec2.SecurityGroup(stack, 'sg1', {
  vpc: vpc,
});
const sg2 = new ec2.SecurityGroup(stack, 'sg2', {
  vpc: vpc,
});

const launchTemplate = new ec2.LaunchTemplate(stack, 'LaunchTemplate', {
  machineImage: ec2.MachineImage.latestAmazonLinux2022(),
  securityGroup: sg1,
});

launchTemplate.addSecurityGroup(sg2);

Properties

NameTypeDescription
blockDevices?BlockDevice[]Specifies how block devices are exposed to the instance. You can specify virtual devices and EBS volumes.
cpuCredits?CpuCreditsCPU credit type for burstable EC2 instance types.
detailedMonitoring?booleanIf set to true, then detailed monitoring will be enabled on instances created with this launch template.
disableApiTermination?booleanIf you set this parameter to true, you cannot terminate the instances launched with this launch template using the Amazon EC2 console, CLI, or API;
ebsOptimized?booleanIndicates whether the instances are optimized for Amazon EBS I/O.
hibernationConfigured?booleanIf you set this parameter to true, the instance is enabled for hibernation.
httpEndpoint?booleanEnables or disables the HTTP metadata endpoint on your instances.
httpProtocolIpv6?booleanEnables or disables the IPv6 endpoint for the instance metadata service.
httpPutResponseHopLimit?numberThe desired HTTP PUT response hop limit for instance metadata requests.
httpTokens?LaunchTemplateHttpTokensThe state of token usage for your instance metadata requests.
instanceInitiatedShutdownBehavior?InstanceInitiatedShutdownBehaviorIndicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).
instanceMetadataTags?booleanSet to enabled to allow access to instance tags from the instance metadata.
instanceType?InstanceTypeType of instance to launch.
keyName?stringName of SSH keypair to grant access to instance.
launchTemplateName?stringName for this launch template.
machineImage?IMachineImageThe AMI that will be used by instances.
nitroEnclaveEnabled?booleanIf this parameter is set to true, the instance is enabled for AWS Nitro Enclaves;
requireImdsv2?booleanWhether IMDSv2 should be required on launched instances.
role?IRoleAn IAM role to associate with the instance profile that is used by instances.
securityGroup?ISecurityGroupSecurity group to assign to instances created with the launch template.
spotOptions?LaunchTemplateSpotOptionsIf this property is defined, then the Launch Template's InstanceMarketOptions will be set to use Spot instances, and the options for the Spot instances will be as defined.
userData?UserDataThe AMI that will be used by instances.

blockDevices?

Type: BlockDevice[] (optional, default: Uses the block device mapping of the AMI)

Specifies how block devices are exposed to the instance. You can specify virtual devices and EBS volumes.

Each instance that is launched has an associated root device volume, either an Amazon EBS volume or an instance store volume. You can use block device mappings to specify additional EBS volumes or instance store volumes to attach to an instance when it is launched.

See also: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/block-device-mapping-concepts.html


cpuCredits?

Type: CpuCredits (optional, default: No credit type is specified in the Launch Template.)

CPU credit type for burstable EC2 instance types.

See also: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/burstable-performance-instances.html


detailedMonitoring?

Type: boolean (optional, default: False - Detailed monitoring is disabled.)

If set to true, then detailed monitoring will be enabled on instances created with this launch template.

See also: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-cloudwatch-new.html


disableApiTermination?

Type: boolean (optional, default: The API termination setting is not specified in the Launch Template.)

If you set this parameter to true, you cannot terminate the instances launched with this launch template using the Amazon EC2 console, CLI, or API;

otherwise, you can.


ebsOptimized?

Type: boolean (optional, default: EBS optimization is not specified in the launch template.)

Indicates whether the instances are optimized for Amazon EBS I/O.

This optimization provides dedicated throughput to Amazon EBS and an optimized configuration stack to provide optimal Amazon EBS I/O performance. This optimization isn't available with all instance types. Additional usage charges apply when using an EBS-optimized instance.


hibernationConfigured?

Type: boolean (optional, default: Hibernation configuration is not specified in the launch template; defaulting to false.)

If you set this parameter to true, the instance is enabled for hibernation.


httpEndpoint?

Type: boolean (optional, default: true)

Enables or disables the HTTP metadata endpoint on your instances.

See also: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-launchtemplatedata-metadataoptions.html#cfn-ec2-launchtemplate-launchtemplatedata-metadataoptions-httpendpoint


httpProtocolIpv6?

Type: boolean (optional, default: true)

Enables or disables the IPv6 endpoint for the instance metadata service.

See also: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-launchtemplatedata-metadataoptions.html#cfn-ec2-launchtemplate-launchtemplatedata-metadataoptions-httpprotocolipv6


httpPutResponseHopLimit?

Type: number (optional, default: 1)

The desired HTTP PUT response hop limit for instance metadata requests.

The larger the number, the further instance metadata requests can travel.

See also: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-launchtemplatedata-metadataoptions.html#cfn-ec2-launchtemplate-launchtemplatedata-metadataoptions-httpputresponsehoplimit


httpTokens?

Type: LaunchTemplateHttpTokens (optional, default: LaunchTemplateHttpTokens.OPTIONAL)

The state of token usage for your instance metadata requests.

The default state is optional if not specified. However, if requireImdsv2 is true, the state must be required.

See also: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-launchtemplatedata-metadataoptions.html#cfn-ec2-launchtemplate-launchtemplatedata-metadataoptions-httptokens


instanceInitiatedShutdownBehavior?

Type: InstanceInitiatedShutdownBehavior (optional, default: Shutdown behavior is not specified in the launch template; defaults to STOP.)

Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).

See also: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/terminating-instances.html#Using_ChangingInstanceInitiatedShutdownBehavior


instanceMetadataTags?

Type: boolean (optional, default: false)

Set to enabled to allow access to instance tags from the instance metadata.

Set to disabled to turn off access to instance tags from the instance metadata.

See also: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-launchtemplate-launchtemplatedata-metadataoptions.html#cfn-ec2-launchtemplate-launchtemplatedata-metadataoptions-instancemetadatatags


instanceType?

Type: InstanceType (optional, default: This Launch Template does not specify a default Instance Type.)

Type of instance to launch.


keyName?

Type: string (optional, default: No SSH access will be possible.)

Name of SSH keypair to grant access to instance.


launchTemplateName?

Type: string (optional, default: Automatically generated name)

Name for this launch template.


machineImage?

Type: IMachineImage (optional, default: This Launch Template does not specify a default AMI.)

The AMI that will be used by instances.


nitroEnclaveEnabled?

Type: boolean (optional, default: Enablement of Nitro enclaves is not specified in the launch template; defaulting to false.)

If this parameter is set to true, the instance is enabled for AWS Nitro Enclaves;

otherwise, it is not enabled for AWS Nitro Enclaves.


requireImdsv2?

Type: boolean (optional, default: false)

Whether IMDSv2 should be required on launched instances.


role?

Type: IRole (optional, default: No new role is created.)

An IAM role to associate with the instance profile that is used by instances.

The role must be assumable by the service principal ec2.amazonaws.com: Example

const role = new iam.Role(this, 'MyRole', {
  assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
});

securityGroup?

Type: ISecurityGroup (optional, default: No security group is assigned.)

Security group to assign to instances created with the launch template.


spotOptions?

Type: LaunchTemplateSpotOptions (optional, default: Instance launched with this template will not be spot instances.)

If this property is defined, then the Launch Template's InstanceMarketOptions will be set to use Spot instances, and the options for the Spot instances will be as defined.


userData?

Type: UserData (optional, default: This Launch Template creates a UserData based on the type of provided machineImage; no UserData is created if a machineImage is not provided)

The AMI that will be used by instances.