LaunchTemplateProps

class aws_cdk.aws_ec2.LaunchTemplateProps(*, associate_public_ip_address=None, block_devices=None, cpu_credits=None, detailed_monitoring=None, disable_api_termination=None, ebs_optimized=None, hibernation_configured=None, http_endpoint=None, http_protocol_ipv6=None, http_put_response_hop_limit=None, http_tokens=None, instance_initiated_shutdown_behavior=None, instance_metadata_tags=None, instance_profile=None, instance_type=None, key_name=None, key_pair=None, launch_template_name=None, machine_image=None, nitro_enclave_enabled=None, require_imdsv2=None, role=None, security_group=None, spot_options=None, user_data=None)

Bases: object

Properties of a LaunchTemplate.

Parameters:
  • associate_public_ip_address (Optional[bool]) – Whether instances should have a public IP addresses associated with them. Default: - Use subnet settings

  • block_devices (Optional[Sequence[Union[BlockDevice, Dict[str, Any]]]]) – 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. Default: - Uses the block device mapping of the AMI

  • cpu_credits (Optional[CpuCredits]) – CPU credit type for burstable EC2 instance types. Default: - No credit type is specified in the Launch Template.

  • detailed_monitoring (Optional[bool]) – If set to true, then detailed monitoring will be enabled on instances created with this launch template. Default: False - Detailed monitoring is disabled.

  • disable_api_termination (Optional[bool]) – 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. Default: - The API termination setting is not specified in the Launch Template.

  • ebs_optimized (Optional[bool]) – 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. Default: - EBS optimization is not specified in the launch template.

  • hibernation_configured (Optional[bool]) – If you set this parameter to true, the instance is enabled for hibernation. Default: - Hibernation configuration is not specified in the launch template; defaulting to false.

  • http_endpoint (Optional[bool]) – Enables or disables the HTTP metadata endpoint on your instances. Default: true

  • http_protocol_ipv6 (Optional[bool]) – Enables or disables the IPv6 endpoint for the instance metadata service. Default: true

  • http_put_response_hop_limit (Union[int, float, None]) – The desired HTTP PUT response hop limit for instance metadata requests. The larger the number, the further instance metadata requests can travel. Default: 1

  • http_tokens (Optional[LaunchTemplateHttpTokens]) – 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. Default: LaunchTemplateHttpTokens.OPTIONAL

  • instance_initiated_shutdown_behavior (Optional[InstanceInitiatedShutdownBehavior]) – Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown). Default: - Shutdown behavior is not specified in the launch template; defaults to STOP.

  • instance_metadata_tags (Optional[bool]) – 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. Default: false

  • instance_profile (Optional[IInstanceProfile]) – The instance profile used to pass role information to EC2 instances. Note: You can provide an instanceProfile or a role, but not both. Default: - No instance profile

  • instance_type (Optional[InstanceType]) – Type of instance to launch. Default: - This Launch Template does not specify a default Instance Type.

  • key_name (Optional[str]) – (deprecated) Name of SSH keypair to grant access to instance. Default: - No SSH access will be possible.

  • key_pair (Optional[IKeyPair]) – The SSH keypair to grant access to the instance. Default: - No SSH access will be possible.

  • launch_template_name (Optional[str]) – Name for this launch template. Default: Automatically generated name

  • machine_image (Optional[IMachineImage]) – The AMI that will be used by instances. Default: - This Launch Template does not specify a default AMI.

  • nitro_enclave_enabled (Optional[bool]) – If this parameter is set to true, the instance is enabled for AWS Nitro Enclaves; otherwise, it is not enabled for AWS Nitro Enclaves. Default: - Enablement of Nitro enclaves is not specified in the launch template; defaulting to false.

  • require_imdsv2 (Optional[bool]) – Whether IMDSv2 should be required on launched instances. Default: - false

  • role (Optional[IRole]) – 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. Note: You can provide an instanceProfile or a role, but not both. Default: - No new role is created.

  • security_group (Optional[ISecurityGroup]) – Security group to assign to instances created with the launch template. Default: No security group is assigned.

  • spot_options (Union[LaunchTemplateSpotOptions, Dict[str, Any], None]) – 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. Default: - Instance launched with this template will not be spot instances.

  • user_data (Optional[UserData]) – The AMI that will be used by instances. Default: - This Launch Template creates a UserData based on the type of provided machineImage; no UserData is created if a machineImage is not provided

ExampleMetadata:

infused

Example:

# vpc: ec2.Vpc


sg1 = ec2.SecurityGroup(self, "sg1",
    vpc=vpc
)
sg2 = ec2.SecurityGroup(self, "sg2",
    vpc=vpc
)

launch_template = ec2.LaunchTemplate(self, "LaunchTemplate",
    machine_image=ec2.MachineImage.latest_amazon_linux2023(),
    security_group=sg1
)

launch_template.add_security_group(sg2)

Attributes

associate_public_ip_address

Whether instances should have a public IP addresses associated with them.

Default:
  • Use subnet settings

block_devices

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.

Default:
  • Uses the block device mapping of the AMI

See:

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

cpu_credits

CPU credit type for burstable EC2 instance types.

Default:
  • No credit type is specified in the Launch Template.

See:

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

detailed_monitoring

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

Default:

False - Detailed monitoring is disabled.

See:

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

disable_api_termination

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.

Default:
  • The API termination setting is not specified in the Launch Template.

ebs_optimized

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.

Default:
  • EBS optimization is not specified in the launch template.

hibernation_configured

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

Default:
  • Hibernation configuration is not specified in the launch template; defaulting to false.

http_endpoint

Enables or disables the HTTP metadata endpoint on your instances.

Default:

true

See:

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

http_protocol_ipv6

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

Default:

true

See:

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

http_put_response_hop_limit

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

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

Default:

1

See:

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

http_tokens

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.

Default:

LaunchTemplateHttpTokens.OPTIONAL

See:

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

instance_initiated_shutdown_behavior

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

Default:
  • Shutdown behavior is not specified in the launch template; defaults to STOP.

See:

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

instance_metadata_tags

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.

Default:

false

See:

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

instance_profile

The instance profile used to pass role information to EC2 instances.

Note: You can provide an instanceProfile or a role, but not both.

Default:
  • No instance profile

instance_type

Type of instance to launch.

Default:
  • This Launch Template does not specify a default Instance Type.

key_name

(deprecated) Name of SSH keypair to grant access to instance.

Default:
  • No SSH access will be possible.

Deprecated:
Stability:

deprecated

key_pair

The SSH keypair to grant access to the instance.

Default:
  • No SSH access will be possible.

launch_template_name

Name for this launch template.

Default:

Automatically generated name

machine_image

The AMI that will be used by instances.

Default:
  • This Launch Template does not specify a default AMI.

nitro_enclave_enabled

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

otherwise, it is not enabled for AWS Nitro Enclaves.

Default:
  • Enablement of Nitro enclaves is not specified in the launch template; defaulting to false.

require_imdsv2

Whether IMDSv2 should be required on launched instances.

Default:
  • false

role

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. Note: You can provide an instanceProfile or a role, but not both.

Default:
  • No new role is created.

Example:

role = iam.Role(self, "MyRole",
    assumed_by=iam.ServicePrincipal("ec2.amazonaws.com")
)
security_group

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

Default:

No security group is assigned.

spot_options

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.

Default:
  • Instance launched with this template will not be spot instances.

user_data

The AMI that will be used by instances.

Default:

  • This Launch Template creates a UserData based on the type of provided

machineImage; no UserData is created if a machineImage is not provided