Class Instance.Builder

java.lang.Object
software.amazon.awscdk.services.ec2.Instance.Builder
All Implemented Interfaces:
software.amazon.jsii.Builder<Instance>
Enclosing class:
Instance

@Stability(Stable) public static final class Instance.Builder extends Object implements software.amazon.jsii.Builder<Instance>
A fluent builder for Instance.
  • 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

      @Stability(Stable) public Instance.Builder instanceType(InstanceType instanceType)
      Type of instance to launch.

      Parameters:
      instanceType - Type of instance to launch. This parameter is required.
      Returns:
      this
    • machineImage

      @Stability(Stable) public Instance.Builder machineImage(IMachineImage machineImage)
      AMI to launch.

      Parameters:
      machineImage - AMI to launch. This parameter is required.
      Returns:
      this
    • vpc

      @Stability(Stable) public Instance.Builder vpc(IVpc vpc)
      VPC to launch the instance in.

      Parameters:
      vpc - VPC to launch the instance in. This parameter is required.
      Returns:
      this
    • allowAllOutbound

      @Stability(Stable) public Instance.Builder allowAllOutbound(Boolean 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
    • availabilityZone

      @Stability(Stable) public Instance.Builder availabilityZone(String 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

      @Stability(Stable) public Instance.Builder blockDevices(List<? extends BlockDevice> 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:
    • detailedMonitoring

      @Stability(Stable) public Instance.Builder detailedMonitoring(Boolean 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:
    • init

      @Stability(Stable) public Instance.Builder init(CloudFormationInit 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

      @Stability(Stable) public Instance.Builder initOptions(ApplyCloudFormationInitOptions 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
    • instanceName

      @Stability(Stable) public Instance.Builder instanceName(String instanceName)
      The name of the instance.

      Default: - CDK generated name

      Parameters:
      instanceName - The name of the instance. This parameter is required.
      Returns:
      this
    • keyName

      @Stability(Stable) public Instance.Builder keyName(String keyName)
      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
    • privateIpAddress

      @Stability(Stable) public Instance.Builder privateIpAddress(String 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

      @Stability(Stable) public Instance.Builder requireImdsv2(Boolean 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

      @Stability(Stable) public Instance.Builder resourceSignalTimeout(Duration 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

      @Stability(Stable) public Instance.Builder role(IRole 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

      @Stability(Stable) public Instance.Builder securityGroup(ISecurityGroup 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

      @Stability(Stable) public Instance.Builder sourceDestCheck(Boolean 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
    • userData

      @Stability(Stable) public Instance.Builder userData(UserData 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 iff `initOptions` is specified, false otherwise.

      Parameters:
      userDataCausesReplacement - Changes to the UserData force replacement. This parameter is required.
      Returns:
      this
    • vpcSubnets

      @Stability(Stable) public Instance.Builder vpcSubnets(SubnetSelection 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

      @Stability(Stable) public Instance build()
      Specified by:
      build in interface software.amazon.jsii.Builder<Instance>
      Returns:
      a newly built instance of Instance.