class Instance (construct)
This represents a single EC2 instance.
new Instance(scope: Construct, id: string, props: InstanceProps)
|instance||Type of instance to launch.|
|machine||AMI to launch.|
|vpc||VPC to launch the instance in.|
|allow||Whether the instance could initiate connections to anywhere by default.|
|availability||In which AZ to place the instance within the VPC.|
|block||Specifies how block devices are exposed to the instance. You can specify virtual devices and EBS volumes.|
|instance||The name of the instance.|
|key||Name of SSH keypair to grant access to instance.|
|private||Defines a private IP address to associate with an instance.|
|resource||The length of time to wait for the resourceSignalCount.|
|role?||An IAM role to associate with the instance profile assigned to this Auto Scaling Group.|
|security||Security Group to assign to this instance.|
|source||Specifies whether to enable an instance launched in a VPC to perform NAT.|
|user||Specific UserData to use.|
|vpc||Where to place the instance within the VPC.|
Type of instance to launch.
AMI to launch.
VPC to launch the instance in.
(optional, default: true)
Whether the instance could initiate connections to anywhere by default.
This property is only used when you do not provide a security group.
(optional, default: Random zone.)
In which AZ to place the instance within the VPC.
(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.
(optional, default: CDK generated name)
The name of the instance.
(optional, default: No SSH access will be possible.)
Name of SSH keypair to grant access to instance.
(optional, default: no association)
Defines a private IP address to associate with an instance.
Private IP should be available within the VPC that the instance is build within.
(optional, default: Duration.minutes(5))
The length of time to wait for the resourceSignalCount.
The maximum value is 43200 (12 hours).
(optional, default: A role will automatically be created, it can be accessed via the
An IAM role to associate with the instance profile assigned to this Auto Scaling Group.
The role must be assumable by the service principal
(optional, default: create new security group)
Security Group to assign to this instance.
(optional, default: true)
Specifies whether to enable an instance launched in a VPC to perform NAT.
This controls whether source/destination checking is enabled on the instance. A value of true means that checking is enabled, and false means that checking is disabled. The value must be false for the instance to perform NAT.
(optional, default: A UserData object appropriate for the MachineImage's
Operating System is created.)
Specific UserData to use.
The UserData may still be mutated after creation.
(optional, default: Private subnets.)
Where to place the instance within the VPC.
|connections||Allows specify security group connections for the instance.|
|grant||The principal to grant permissions to.|
|instance||the underlying instance resource.|
|instance||The availability zone the instance was launched in.|
|instance||The instance's ID.|
|instance||Private DNS name for this instance.|
|instance||Private IP for this instance.|
|instance||Publicly-routable DNS name for this instance.|
|instance||Publicly-routable IP address for this instance.|
|node||The construct tree node associated with this construct.|
|os||The type of OS the instance is running.|
|role||The IAM role assumed by the instance.|
|stack||The stack in which this resource is defined.|
|user||UserData for the instance.|
Allows specify security group connections for the instance.
The principal to grant permissions to.
the underlying instance resource.
The availability zone the instance was launched in.
The instance's ID.
Private DNS name for this instance.
Private IP for this instance.
Publicly-routable DNS name for this instance.
(May be an empty string if the instance does not have a public name).
Publicly-routable IP address for this instance.
(May be an empty string if the instance does not have a public IP).
The construct tree node associated with this construct.
The type of OS the instance is running.
The IAM role assumed by the instance.
The stack in which this resource is defined.
UserData for the instance.
|add||Add the security group to the instance.|
|add||Adds a statement to the IAM role assumed by the instance.|
|add||Add command to the startup script of the instance.|
|to||Returns a string representation of this construct.|
public addSecurityGroup(securityGroup: ISecurityGroup): void
ISecurity— : The security group to add.
Add the security group to the instance.
To Role Policy(statement)
public addToRolePolicy(statement: PolicyStatement): void
Adds a statement to the IAM role assumed by the instance.
public addUserData(...commands: string): void
Add command to the startup script of the instance.
The command must be in the scripting language supported by the instance's OS (i.e. Linux/Windows).
public toString(): string
Returns a string representation of this construct.