Class InstanceProps.Builder

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

@Stability(Stable) public static final class InstanceProps.Builder extends Object implements software.amazon.jsii.Builder<InstanceProps>
A builder for InstanceProps
  • Constructor Details

    • Builder

      public Builder()
  • Method Details

    • instanceType

      @Stability(Stable) public InstanceProps.Builder instanceType(InstanceType instanceType)
      Parameters:
      instanceType - Type of instance to launch. This parameter is required.
      Returns:
      this
    • machineImage

      @Stability(Stable) public InstanceProps.Builder machineImage(IMachineImage machineImage)
      Parameters:
      machineImage - AMI to launch. This parameter is required.
      Returns:
      this
    • vpc

      @Stability(Stable) public InstanceProps.Builder vpc(IVpc vpc)
      Sets the value of InstanceProps.getVpc()
      Parameters:
      vpc - VPC to launch the instance in. This parameter is required.
      Returns:
      this
    • allowAllOutbound

      @Stability(Stable) public InstanceProps.Builder allowAllOutbound(Boolean allowAllOutbound)
      Parameters:
      allowAllOutbound - Whether the instance could initiate connections to anywhere by default. This property is only used when you do not provide a security group.
      Returns:
      this
    • availabilityZone

      @Stability(Stable) public InstanceProps.Builder availabilityZone(String availabilityZone)
      Parameters:
      availabilityZone - In which AZ to place the instance within the VPC.
      Returns:
      this
    • blockDevices

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

      @Stability(Stable) public InstanceProps.Builder detailedMonitoring(Boolean detailedMonitoring)
      Parameters:
      detailedMonitoring - Whether "Detailed Monitoring" is enabled for this instance Keep in mind that Detailed Monitoring results in extra charges.
      Returns:
      this
    • init

      @Stability(Stable) public InstanceProps.Builder init(CloudFormationInit init)
      Sets the value of InstanceProps.getInit()
      Parameters:
      init - Apply the given CloudFormation Init configuration to the instance at startup.
      Returns:
      this
    • initOptions

      @Stability(Stable) public InstanceProps.Builder initOptions(ApplyCloudFormationInitOptions initOptions)
      Parameters:
      initOptions - Use the given options for applying CloudFormation Init. Describes the configsets to use and the timeout to wait
      Returns:
      this
    • instanceName

      @Stability(Stable) public InstanceProps.Builder instanceName(String instanceName)
      Parameters:
      instanceName - The name of the instance.
      Returns:
      this
    • keyName

      @Stability(Stable) public InstanceProps.Builder keyName(String keyName)
      Sets the value of InstanceProps.getKeyName()
      Parameters:
      keyName - Name of SSH keypair to grant access to instance.
      Returns:
      this
    • privateIpAddress

      @Stability(Stable) public InstanceProps.Builder privateIpAddress(String privateIpAddress)
      Parameters:
      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.
      Returns:
      this
    • propagateTagsToVolumeOnCreation

      @Stability(Stable) public InstanceProps.Builder propagateTagsToVolumeOnCreation(Boolean propagateTagsToVolumeOnCreation)
      Parameters:
      propagateTagsToVolumeOnCreation - Propagate the EC2 instance tags to the EBS volumes.
      Returns:
      this
    • requireImdsv2

      @Stability(Stable) public InstanceProps.Builder requireImdsv2(Boolean requireImdsv2)
      Parameters:
      requireImdsv2 - Whether IMDSv2 should be required on this instance.
      Returns:
      this
    • resourceSignalTimeout

      @Stability(Stable) public InstanceProps.Builder resourceSignalTimeout(Duration resourceSignalTimeout)
      Parameters:
      resourceSignalTimeout - The length of time to wait for the resourceSignalCount. The maximum value is 43200 (12 hours).
      Returns:
      this
    • role

      @Stability(Stable) public InstanceProps.Builder role(IRole role)
      Sets the value of InstanceProps.getRole()
      Parameters:
      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:
      Returns:
      this
    • securityGroup

      @Stability(Stable) public InstanceProps.Builder securityGroup(ISecurityGroup securityGroup)
      Parameters:
      securityGroup - Security Group to assign to this instance.
      Returns:
      this
    • sourceDestCheck

      @Stability(Stable) public InstanceProps.Builder sourceDestCheck(Boolean sourceDestCheck)
      Parameters:
      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.
      Returns:
      this
    • userData

      @Stability(Stable) public InstanceProps.Builder userData(UserData userData)
      Sets the value of InstanceProps.getUserData()
      Parameters:
      userData - Specific UserData to use. The UserData may still be mutated after creation.
      Returns:
      this
    • userDataCausesReplacement

      @Stability(Stable) public InstanceProps.Builder userDataCausesReplacement(Boolean userDataCausesReplacement)
      Parameters:
      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.

      Returns:
      this
    • vpcSubnets

      @Stability(Stable) public InstanceProps.Builder vpcSubnets(SubnetSelection vpcSubnets)
      Parameters:
      vpcSubnets - Where to place the instance within the VPC.
      Returns:
      this
    • build

      @Stability(Stable) public InstanceProps build()
      Builds the configured instance.
      Specified by:
      build in interface software.amazon.jsii.Builder<InstanceProps>
      Returns:
      a new instance of InstanceProps
      Throws:
      NullPointerException - if any required attribute was not provided