Class Instance.Builder
- All Implemented Interfaces:
software.amazon.jsii.Builder<Instance>
- Enclosing class:
Instance
Instance
.-
Method Summary
Modifier and TypeMethodDescriptionallowAllIpv6Outbound
(Boolean allowAllIpv6Outbound) Whether the instance could initiate IPv6 connections to anywhere by default.allowAllOutbound
(Boolean allowAllOutbound) Whether the instance could initiate connections to anywhere by default.associatePublicIpAddress
(Boolean associatePublicIpAddress) Whether to associate a public IP address to the primary network interface attached to this instance.availabilityZone
(String availabilityZone) In which AZ to place the instance within the VPC.blockDevices
(List<? extends BlockDevice> blockDevices) Specifies how block devices are exposed to the instance.build()
static Instance.Builder
creditSpecification
(CpuCredits creditSpecification) Specifying the CPU credit type for burstable EC2 instance types (T2, T3, T3a, etc).detailedMonitoring
(Boolean detailedMonitoring) Whether "Detailed Monitoring" is enabled for this instance Keep in mind that Detailed Monitoring results in extra charges.disableApiTermination
(Boolean disableApiTermination) If true, the instance will not be able to be terminated using the Amazon EC2 console, CLI, or API.ebsOptimized
(Boolean ebsOptimized) Indicates whether the instance is optimized for Amazon EBS I/O.enclaveEnabled
(Boolean enclaveEnabled) Whether the instance is enabled for AWS Nitro Enclaves.hibernationEnabled
(Boolean hibernationEnabled) Whether the instance is enabled for hibernation.init
(CloudFormationInit init) Apply the given CloudFormation Init configuration to the instance at startup.initOptions
(ApplyCloudFormationInitOptions initOptions) Use the given options for applying CloudFormation Init.instanceInitiatedShutdownBehavior
(InstanceInitiatedShutdownBehavior instanceInitiatedShutdownBehavior) Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).instanceName
(String instanceName) The name of the instance.instanceType
(InstanceType instanceType) Type of instance to launch.ipv6AddressCount
(Number ipv6AddressCount) The number of IPv6 addresses to associate with the primary network interface.Deprecated.The SSH keypair to grant access to the instance.machineImage
(IMachineImage machineImage) AMI to launch.placementGroup
(IPlacementGroup placementGroup) The placement group that you want to launch the instance into.privateIpAddress
(String privateIpAddress) Defines a private IP address to associate with an instance.propagateTagsToVolumeOnCreation
(Boolean propagateTagsToVolumeOnCreation) Propagate the EC2 instance tags to the EBS volumes.requireImdsv2
(Boolean requireImdsv2) Whether IMDSv2 should be required on this instance.resourceSignalTimeout
(Duration resourceSignalTimeout) The length of time to wait for the resourceSignalCount.An IAM role to associate with the instance profile assigned to this Auto Scaling Group.securityGroup
(ISecurityGroup securityGroup) Security Group to assign to this instance.sourceDestCheck
(Boolean sourceDestCheck) Specifies whether to enable an instance launched in a VPC to perform NAT.ssmSessionPermissions
(Boolean ssmSessionPermissions) Add SSM session permissions to the instance role.Specific UserData to use.userDataCausesReplacement
(Boolean userDataCausesReplacement) Changes to the UserData force replacement.VPC to launch the instance in.vpcSubnets
(SubnetSelection vpcSubnets) Where to place the instance within the VPC.
-
Method Details
-
create
@Stability(Stable) public static Instance.Builder create(software.constructs.Construct scope, String id) - Parameters:
scope
- This parameter is required.id
- This parameter is required.- Returns:
- a new instance of
Instance.Builder
.
-
instanceType
Type of instance to launch.- Parameters:
instanceType
- Type of instance to launch. This parameter is required.- Returns:
this
-
machineImage
AMI to launch.- Parameters:
machineImage
- AMI to launch. This parameter is required.- Returns:
this
-
vpc
VPC to launch the instance in.- Parameters:
vpc
- VPC to launch the instance in. This parameter is required.- Returns:
this
-
allowAllIpv6Outbound
Whether the instance could initiate IPv6 connections to anywhere by default.This property is only used when you do not provide a security group.
Default: false
- Parameters:
allowAllIpv6Outbound
- Whether the instance could initiate IPv6 connections to anywhere by default. This parameter is required.- Returns:
this
-
allowAllOutbound
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
- Parameters:
allowAllOutbound
- Whether the instance could initiate connections to anywhere by default. This parameter is required.- Returns:
this
-
associatePublicIpAddress
@Stability(Stable) public Instance.Builder associatePublicIpAddress(Boolean associatePublicIpAddress) Whether to associate a public IP address to the primary network interface attached to this instance.You cannot specify this property and
ipv6AddressCount
at the same time.Default: - public IP address is automatically assigned based on default behavior
- Parameters:
associatePublicIpAddress
- Whether to associate a public IP address to the primary network interface attached to this instance. This parameter is required.- Returns:
this
-
availabilityZone
In which AZ to place the instance within the VPC.Default: - Random zone.
- Parameters:
availabilityZone
- In which AZ to place the instance within the VPC. This parameter is required.- Returns:
this
-
blockDevices
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
- Parameters:
blockDevices
- Specifies how block devices are exposed to the instance. You can specify virtual devices and EBS volumes. This parameter is required.- Returns:
this
- See Also:
-
creditSpecification
Specifying the CPU credit type for burstable EC2 instance types (T2, T3, T3a, etc).The unlimited CPU credit option is not supported for T3 instances with a dedicated host.
Default: - T2 instances are standard, while T3, T4g, and T3a instances are unlimited.
- Parameters:
creditSpecification
- Specifying the CPU credit type for burstable EC2 instance types (T2, T3, T3a, etc). This parameter is required.- Returns:
this
-
detailedMonitoring
Whether "Detailed Monitoring" is enabled for this instance Keep in mind that Detailed Monitoring results in extra charges.Default: - false
- Parameters:
detailedMonitoring
- Whether "Detailed Monitoring" is enabled for this instance Keep in mind that Detailed Monitoring results in extra charges. This parameter is required.- Returns:
this
- See Also:
-
disableApiTermination
If true, the instance will not be able to be terminated using the Amazon EC2 console, CLI, or API.To change this attribute after launch, use ModifyInstanceAttribute. Alternatively, if you set InstanceInitiatedShutdownBehavior to terminate, you can terminate the instance by running the shutdown command from the instance.
Default: false
- Parameters:
disableApiTermination
- If true, the instance will not be able to be terminated using the Amazon EC2 console, CLI, or API. This parameter is required.- Returns:
this
- See Also:
-
ebsOptimized
Indicates whether the instance is 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: false
- Parameters:
ebsOptimized
- Indicates whether the instance is optimized for Amazon EBS I/O. This parameter is required.- Returns:
this
-
enclaveEnabled
Whether the instance is enabled for AWS Nitro Enclaves.Nitro Enclaves requires a Nitro-based virtualized parent instance with specific Intel/AMD with at least 4 vCPUs or Graviton with at least 2 vCPUs instance types and Linux/Windows host OS, while the enclave itself supports only Linux OS.
You can't set both
enclaveEnabled
andhibernationEnabled
to true on the same instance.Default: - false
- Parameters:
enclaveEnabled
- Whether the instance is enabled for AWS Nitro Enclaves. This parameter is required.- Returns:
this
- See Also:
-
hibernationEnabled
Whether the instance is enabled for hibernation.You can't set both
enclaveEnabled
andhibernationEnabled
to true on the same instance.Default: - false
- Parameters:
hibernationEnabled
- Whether the instance is enabled for hibernation. This parameter is required.- Returns:
this
- See Also:
-
init
Apply the given CloudFormation Init configuration to the instance at startup.Default: - no CloudFormation init
- Parameters:
init
- Apply the given CloudFormation Init configuration to the instance at startup. This parameter is required.- Returns:
this
-
initOptions
Use the given options for applying CloudFormation Init.Describes the configsets to use and the timeout to wait
Default: - default options
- Parameters:
initOptions
- Use the given options for applying CloudFormation Init. This parameter is required.- Returns:
this
-
instanceInitiatedShutdownBehavior
@Stability(Stable) public Instance.Builder instanceInitiatedShutdownBehavior(InstanceInitiatedShutdownBehavior instanceInitiatedShutdownBehavior) Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).Default: InstanceInitiatedShutdownBehavior.STOP
- Parameters:
instanceInitiatedShutdownBehavior
- Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown). This parameter is required.- Returns:
this
- See Also:
-
instanceName
The name of the instance.Default: - CDK generated name
- Parameters:
instanceName
- The name of the instance. This parameter is required.- Returns:
this
-
ipv6AddressCount
The number of IPv6 addresses to associate with the primary network interface.Amazon EC2 chooses the IPv6 addresses from the range of your subnet.
You cannot specify this property and
associatePublicIpAddress
at the same time.Default: - For instances associated with an IPv6 subnet, use 1; otherwise, use 0.
- Parameters:
ipv6AddressCount
- The number of IPv6 addresses to associate with the primary network interface. This parameter is required.- Returns:
this
-
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
(deprecated) Name of SSH keypair to grant access to instance.Default: - No SSH access will be possible.
- Parameters:
keyName
- Name of SSH keypair to grant access to instance. This parameter is required.- Returns:
this
- Use
-
keyPair
The SSH keypair to grant access to the instance.Default: - No SSH access will be possible.
- Parameters:
keyPair
- The SSH keypair to grant access to the instance. This parameter is required.- Returns:
this
-
placementGroup
The placement group that you want to launch the instance into.Default: - no placement group will be used for this instance.
- Parameters:
placementGroup
- The placement group that you want to launch the instance into. This parameter is required.- Returns:
this
-
privateIpAddress
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
- Parameters:
privateIpAddress
- Defines a private IP address to associate with an instance. This parameter is required.- Returns:
this
-
propagateTagsToVolumeOnCreation
@Stability(Stable) public Instance.Builder propagateTagsToVolumeOnCreation(Boolean propagateTagsToVolumeOnCreation) Propagate the EC2 instance tags to the EBS volumes.Default: - false
- Parameters:
propagateTagsToVolumeOnCreation
- Propagate the EC2 instance tags to the EBS volumes. This parameter is required.- Returns:
this
-
requireImdsv2
Whether IMDSv2 should be required on this instance.Default: - false
- Parameters:
requireImdsv2
- Whether IMDSv2 should be required on this instance. This parameter is required.- Returns:
this
-
resourceSignalTimeout
The length of time to wait for the resourceSignalCount.The maximum value is 43200 (12 hours).
Default: Duration.minutes(5)
- Parameters:
resourceSignalTimeout
- The length of time to wait for the resourceSignalCount. This parameter is required.- Returns:
this
-
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:
Role role = Role.Builder.create(this, "MyRole") .assumedBy(new ServicePrincipal("ec2.amazonaws.com")) .build();
- Parameters:
role
- An IAM role to associate with the instance profile assigned to this Auto Scaling Group. This parameter is required.- Returns:
this
-
securityGroup
Security Group to assign to this instance.Default: - create new security group
- Parameters:
securityGroup
- Security Group to assign to this instance. This parameter is required.- Returns:
this
-
sourceDestCheck
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
- Parameters:
sourceDestCheck
- Specifies whether to enable an instance launched in a VPC to perform NAT. This parameter is required.- Returns:
this
-
ssmSessionPermissions
Add SSM session permissions to the instance role.Setting this to
true
adds the necessary permissions to connect to the instance using SSM Session Manager. You can do this from the AWS Console.NOTE: Setting this flag to
true
may not be enough by itself. You must also use an AMI that comes with the SSM Agent, or install the SSM Agent yourself. See Working with SSM Agent in the SSM Developer Guide.Default: false
- Parameters:
ssmSessionPermissions
- Add SSM session permissions to the instance role. This parameter is required.- Returns:
this
-
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.
- Parameters:
userData
- Specific UserData to use. This parameter is required.- Returns:
this
-
userDataCausesReplacement
@Stability(Stable) public Instance.Builder userDataCausesReplacement(Boolean userDataCausesReplacement) 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 if `initOptions` is specified, false otherwise.
- Parameters:
userDataCausesReplacement
- Changes to the UserData force replacement. This parameter is required.- Returns:
this
-
vpcSubnets
Where to place the instance within the VPC.Default: - Private subnets.
- Parameters:
vpcSubnets
- Where to place the instance within the VPC. This parameter is required.- Returns:
this
-
build
-
keyPair
instead - https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_ec2-readme.html#using-an-existing-ec2-key-pair