class LaunchTemplate (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.EC2.LaunchTemplate |
Go | github.com/aws/aws-cdk-go/awscdk/v2/awsec2#LaunchTemplate |
Java | software.amazon.awscdk.services.ec2.LaunchTemplate |
Python | aws_cdk.aws_ec2.LaunchTemplate |
TypeScript (source) | aws-cdk-lib » aws_ec2 » LaunchTemplate |
Implements
IConstruct
, IDependable
, IResource
, ILaunch
, IGrantable
, IConnectable
This represents an EC2 LaunchTemplate.
See also: https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-launch-templates.html
Example
declare const vpc: ec2.Vpc;
const sg1 = new ec2.SecurityGroup(this, 'sg1', {
vpc: vpc,
});
const sg2 = new ec2.SecurityGroup(this, 'sg2', {
vpc: vpc,
});
const launchTemplate = new ec2.LaunchTemplate(this, 'LaunchTemplate', {
machineImage: ec2.MachineImage.latestAmazonLinux2023(),
securityGroup: sg1,
});
launchTemplate.addSecurityGroup(sg2);
Initializer
new LaunchTemplate(scope: Construct, id: string, props?: LaunchTemplateProps)
Parameters
- scope
Construct
- id
string
- props
Launch
Template Props
Construct Props
Name | Type | Description |
---|---|---|
associate | boolean | Whether instances should have a public IP addresses associated with them. |
block | Block [] | Specifies how block devices are exposed to the instance. You can specify virtual devices and EBS volumes. |
cpu | Cpu | CPU credit type for burstable EC2 instance types. |
detailed | boolean | If set to true, then detailed monitoring will be enabled on instances created with this launch template. |
disable | boolean | 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; |
ebs | boolean | Indicates whether the instances are optimized for Amazon EBS I/O. |
hibernation | boolean | If you set this parameter to true, the instance is enabled for hibernation. |
http | boolean | Enables or disables the HTTP metadata endpoint on your instances. |
http | boolean | Enables or disables the IPv6 endpoint for the instance metadata service. |
http | number | The desired HTTP PUT response hop limit for instance metadata requests. |
http | Launch | The state of token usage for your instance metadata requests. |
instance | Instance | Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown). |
instance | boolean | Set to enabled to allow access to instance tags from the instance metadata. |
instance | IInstance | The instance profile used to pass role information to EC2 instances. |
instance | Instance | Type of instance to launch. |
key | string | Name of SSH keypair to grant access to instance. |
key | IKey | The SSH keypair to grant access to the instance. |
launch | string | Name for this launch template. |
machine | IMachine | The AMI that will be used by instances. |
nitro | boolean | If this parameter is set to true, the instance is enabled for AWS Nitro Enclaves; |
require | boolean | Whether IMDSv2 should be required on launched instances. |
role? | IRole | An IAM role to associate with the instance profile that is used by instances. |
security | ISecurity | Security group to assign to instances created with the launch template. |
spot | Launch | 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. |
user | User | The AMI that will be used by instances. |
version | string | A description for the first version of the launch template. |
associatePublicIpAddress?
Type:
boolean
(optional, default: Use subnet settings)
Whether instances should have a public IP addresses associated with them.
blockDevices?
Type:
Block
[]
(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.
cpuCredits?
Type:
Cpu
(optional, default: No credit type is specified in the Launch Template.)
CPU credit type for burstable EC2 instance types.
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.
httpProtocolIpv6?
Type:
boolean
(optional, default: true)
Enables or disables the IPv6 endpoint for the instance metadata service.
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.
httpTokens?
Type:
Launch
(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
.
instanceInitiatedShutdownBehavior?
Type:
Instance
(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).
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.
instanceProfile?
Type:
IInstance
(optional, default: No 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.
instanceType?
Type:
Instance
(optional, default: This Launch Template does not specify a default Instance Type.)
Type of instance to launch.
keyName?
⚠️ Deprecated: - Use keyPair
instead - https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2-readme.html#using-an-existing-ec2-key-pair
Type:
string
(optional, default: No SSH access will be possible.)
Name of SSH keypair to grant access to instance.
keyPair?
Type:
IKey
(optional, default: No SSH access will be possible.)
The SSH keypair to grant access to the instance.
launchTemplateName?
Type:
string
(optional, default: Automatically generated name)
Name for this launch template.
machineImage?
Type:
IMachine
(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
.
Note: You can provide an instanceProfile or a role, but not both.
Example
const role = new iam.Role(this, 'MyRole', {
assumedBy: new iam.ServicePrincipal('ec2.amazonaws.com')
});
securityGroup?
Type:
ISecurity
(optional, default: No security group is assigned.)
Security group to assign to instances created with the launch template.
spotOptions?
Type:
Launch
(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:
User
(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.
versionDescription?
Type:
string
(optional, default: No description)
A description for the first version of the launch template.
The version description must be maximum 255 characters long.
Properties
Name | Type | Description |
---|---|---|
connections | Connections | Allows specifying security group connections for the instance. |
default | string | The default version for the launch template. |
env | Resource | The environment this resource belongs to. |
grant | IPrincipal | Principal to grant permissions to. |
latest | string | The latest version of the launch template. |
node | Node | The tree node. |
stack | Stack | The stack in which this resource is defined. |
tags | Tag | TagManager for tagging support. |
version | string | The version number of this launch template to use. |
image | string | The AMI ID of the image to use. |
instance | Instance | Type of instance to launch. |
launch | string | The identifier of the Launch Template. |
launch | string | The name of the Launch Template. |
os | Operating | The type of OS the instance is running. |
role? | IRole | IAM Role assumed by instances that are launched from this template. |
user | User | UserData executed by instances that are launched from this template. |
connections
Type:
Connections
Allows specifying security group connections for the instance.
defaultVersionNumber
Type:
string
The default version for the launch template.
env
Type:
Resource
The environment this resource belongs to.
For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.
grantPrincipal
Type:
IPrincipal
Principal to grant permissions to.
latestVersionNumber
Type:
string
The latest version of the launch template.
node
Type:
Node
The tree node.
stack
Type:
Stack
The stack in which this resource is defined.
tags
Type:
Tag
TagManager for tagging support.
versionNumber
Type:
string
The version number of this launch template to use.
imageId?
Type:
string
(optional)
The AMI ID of the image to use.
instanceType?
Type:
Instance
(optional)
Type of instance to launch.
launchTemplateId?
Type:
string
(optional)
The identifier of the Launch Template.
Exactly one of launchTemplateId
and launchTemplateName
will be set.
launchTemplateName?
Type:
string
(optional)
The name of the Launch Template.
Exactly one of launchTemplateId
and launchTemplateName
will be set.
osType?
Type:
Operating
(optional)
The type of OS the instance is running.
role?
Type:
IRole
(optional)
IAM Role assumed by instances that are launched from this template.
userData?
Type:
User
(optional)
UserData executed by instances that are launched from this template.
Methods
Name | Description |
---|---|
add | Add the security group to the instance. |
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
static from | Import an existing LaunchTemplate. |
SecurityGroup(securityGroup)
addpublic addSecurityGroup(securityGroup: ISecurityGroup): void
Parameters
- securityGroup
ISecurity
— : The security group to add.Group
Add the security group to the instance.
RemovalPolicy(policy)
applypublic applyRemovalPolicy(policy: RemovalPolicy): void
Parameters
- policy
Removal
Policy
Apply the given removal policy to this resource.
The Removal Policy controls what happens to this resource when it stops being managed by CloudFormation, either because you've removed it from the CDK application or because you've made a change that requires the resource to be replaced.
The resource can be deleted (RemovalPolicy.DESTROY
), or left in your AWS
account for data recovery and cleanup later (RemovalPolicy.RETAIN
).
String()
topublic toString(): string
Returns
string
Returns a string representation of this construct.
LaunchTemplateAttributes(scope, id, attrs)
static frompublic static fromLaunchTemplateAttributes(scope: Construct, id: string, attrs: LaunchTemplateAttributes): ILaunchTemplate
Parameters
- scope
Construct
- id
string
- attrs
Launch
Template Attributes
Returns
Import an existing LaunchTemplate.