InstanceProps¶
-
class
aws_cdk.aws_ec2.
InstanceProps
(*, instance_type, machine_image, vpc, allow_all_outbound=None, availability_zone=None, block_devices=None, init=None, init_options=None, instance_name=None, key_name=None, private_ip_address=None, resource_signal_timeout=None, role=None, security_group=None, source_dest_check=None, user_data=None, user_data_causes_replacement=None, vpc_subnets=None)¶ Bases:
object
Properties of an EC2 Instance.
- Parameters
instance_type (
InstanceType
) – Type of instance to launch.machine_image (
IMachineImage
) – AMI to launch.vpc (
IVpc
) – VPC to launch the instance in.allow_all_outbound (
Optional
[bool
]) – Whether the instance could initiate connections to anywhere by default. This property is only used when you do not provide a security group. Default: trueavailability_zone (
Optional
[str
]) – In which AZ to place the instance within the VPC. Default: - Random zone.block_devices (
Optional
[List
[BlockDevice
]]) – 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 AMIinit (
Optional
[CloudFormationInit
]) – Apply the given CloudFormation Init configuration to the instance at startup. Default: - no CloudFormation initinit_options (
Optional
[ApplyCloudFormationInitOptions
]) – Use the given options for applying CloudFormation Init. Describes the configsets to use and the timeout to wait Default: - default optionsinstance_name (
Optional
[str
]) – The name of the instance. Default: - CDK generated namekey_name (
Optional
[str
]) – Name of SSH keypair to grant access to instance. Default: - No SSH access will be possible.private_ip_address (
Optional
[str
]) – Defines a private IP address to associate with an instance. Private IP should be available within the VPC that the instance is build within. Default: - no associationresource_signal_timeout (
Optional
[Duration
]) – The length of time to wait for the resourceSignalCount. The maximum value is 43200 (12 hours). Default: Duration.minutes(5)role (
Optional
[IRole
]) – An IAM role to associate with the instance profile assigned to this Auto Scaling Group. The role must be assumable by the service principalec2.amazonaws.com
: Default: - A role will automatically be created, it can be accessed via therole
propertysecurity_group (
Optional
[ISecurityGroup
]) – Security Group to assign to this instance. Default: - create new security groupsource_dest_check (
Optional
[bool
]) – 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. Default: trueuser_data (
Optional
[UserData
]) – Specific UserData to use. The UserData may still be mutated after creation. Default: - A UserData object appropriate for the MachineImage’s Operating System is created.user_data_causes_replacement (
Optional
[bool
]) – Changes to the UserData force replacement. Depending the EC2 instance type, changing UserData either restarts the instance or replaces the instance. - Instance store-backed instances are replaced. - EBS-backed instances are restarted. By default, restarting does not execute the new UserData so you will need a different mechanism to ensure the instance is restarted. Setting this totrue
will make the instance’s Logical ID depend on the UserData, which will cause CloudFormation to replace it if the UserData changes. Default: - true iffinitOptions
is specified, false otherwise.vpc_subnets (
Optional
[SubnetSelection
]) – Where to place the instance within the VPC. Default: - Private subnets.
Attributes
-
allow_all_outbound
¶ Whether the instance could initiate connections to anywhere by default.
This property is only used when you do not provide a security group.
- Default
true
- Return type
Optional
[bool
]
-
availability_zone
¶ In which AZ to place the instance within the VPC.
- Default
Random zone.
- Return type
Optional
[str
]
-
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
- Return type
Optional
[List
[BlockDevice
]]
-
init
¶ Apply the given CloudFormation Init configuration to the instance at startup.
- Default
no CloudFormation init
- Return type
Optional
[CloudFormationInit
]
-
init_options
¶ Use the given options for applying CloudFormation Init.
Describes the configsets to use and the timeout to wait
- Default
default options
- Return type
Optional
[ApplyCloudFormationInitOptions
]
-
instance_name
¶ The name of the instance.
- Default
CDK generated name
- Return type
Optional
[str
]
-
instance_type
¶ Type of instance to launch.
- Return type
-
key_name
¶ Name of SSH keypair to grant access to instance.
- Default
No SSH access will be possible.
- Return type
Optional
[str
]
-
machine_image
¶ AMI to launch.
- Return type
-
private_ip_address
¶ Defines a private IP address to associate with an instance.
Private IP should be available within the VPC that the instance is build within.
- Default
no association
- Return type
Optional
[str
]
-
resource_signal_timeout
¶ The length of time to wait for the resourceSignalCount.
The maximum value is 43200 (12 hours).
- Default
Duration.minutes(5)
- Return type
Optional
[Duration
]
-
role
¶ An IAM role to associate with the instance profile assigned to this Auto Scaling Group.
The role must be assumable by the service principal
ec2.amazonaws.com
:- Default
A role will automatically be created, it can be accessed via the
role
property
Example:
# Example automatically generated. See https://github.com/aws/jsii/issues/826 role = iam.Role(self, "MyRole", assumed_by=iam.ServicePrincipal("ec2.amazonaws.com") )
- Return type
Optional
[IRole
]
-
security_group
¶ Security Group to assign to this instance.
- Default
create new security group
- Return type
Optional
[ISecurityGroup
]
-
source_dest_check
¶ 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.
- Default
true
- Return type
Optional
[bool
]
-
user_data
¶ Specific UserData to use.
The UserData may still be mutated after creation.
- Default
A UserData object appropriate for the MachineImage’s
Operating System is created.
- Return type
Optional
[UserData
]
-
user_data_causes_replacement
¶ Changes to the UserData force replacement.
Depending the EC2 instance type, changing UserData either restarts the instance or replaces the instance.
Instance store-backed instances are replaced.
EBS-backed instances are restarted.
By default, restarting does not execute the new UserData so you will need a different mechanism to ensure the instance is restarted.
Setting this to
true
will make the instance’s Logical ID depend on the UserData, which will cause CloudFormation to replace it if the UserData changes.- Default
true iff
initOptions
is specified, false otherwise.
- Return type
Optional
[bool
]
-
vpc_subnets
¶ Where to place the instance within the VPC.
- Default
Private subnets.
- Return type
Optional
[SubnetSelection
]