class LaunchTemplate (construct)
Language | Type name |
---|---|
.NET | Amazon.CDK.AWS.EC2.LaunchTemplate |
Java | software.amazon.awscdk.services.ec2.LaunchTemplate |
Python | aws_cdk.aws_ec2.LaunchTemplate |
TypeScript (source) | @aws-cdk/aws-ec2 » LaunchTemplate |
Implements
IConstruct
, 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
const bootHookConf = ec2.UserData.forLinux();
bootHookConf.addCommands('cloud-init-per once docker_options echo \'OPTIONS="${OPTIONS} --storage-opt dm.basesize=40G"\' >> /etc/sysconfig/docker');
const setupCommands = ec2.UserData.forLinux();
setupCommands.addCommands('sudo yum install awscli && echo Packages installed らと > /var/tmp/setup');
const multipartUserData = new ec2.MultipartUserData();
// The docker has to be configured at early stage, so content type is overridden to boothook
multipartUserData.addPart(ec2.MultipartBody.fromUserData(bootHookConf, 'text/cloud-boothook; charset="us-ascii"'));
// Execute the rest of setup
multipartUserData.addPart(ec2.MultipartBody.fromUserData(setupCommands));
new ec2.LaunchTemplate(this, '', {
userData: multipartUserData,
blockDevices: [
// Block device configuration rest
]
});
Initializer
new LaunchTemplate(scope: Construct, id: string, props?: LaunchTemplateProps)
Parameters
- scope
Construct
- id
string
- props
Launch
Template Props
Construct Props
Name | Type | Description |
---|---|---|
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. |
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 | Instance | Type of instance to launch. |
key | string | Name of SSH keypair to grant access to 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. |
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.
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).
instanceType?
Type:
Instance
(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:
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
:
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.
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 | Construct | The construct tree node associated with this construct. |
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:
Construct
The construct tree node associated with this construct.
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 |
---|---|
apply | Apply the given removal policy to this resource. |
to | Returns a string representation of this construct. |
static from | Import an existing LaunchTemplate. |
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.