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
    • allowAllIpv6Outbound

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

      @Stability(Stable) public InstanceProps.Builder associatePublicIpAddress(Boolean associatePublicIpAddress)
      Parameters:
      associatePublicIpAddress - Whether to associate a public IP address to the primary network interface attached to this instance.
      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
    • creditSpecification

      @Stability(Stable) public InstanceProps.Builder creditSpecification(CpuCredits creditSpecification)
      Parameters:
      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.
      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
    • ebsOptimized

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

      @Stability(Stable) public InstanceProps.Builder enclaveEnabled(Boolean enclaveEnabled)
      Parameters:
      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 and hibernationEnabled to true on the same instance.

      Returns:
      this
    • hibernationEnabled

      @Stability(Stable) public InstanceProps.Builder hibernationEnabled(Boolean hibernationEnabled)
      Parameters:
      hibernationEnabled - Whether the instance is enabled for hibernation. You can't set both enclaveEnabled and hibernationEnabled to true on the same instance.
      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
    • instanceInitiatedShutdownBehavior

      @Stability(Stable) public InstanceProps.Builder instanceInitiatedShutdownBehavior(InstanceInitiatedShutdownBehavior instanceInitiatedShutdownBehavior)
      Parameters:
      instanceInitiatedShutdownBehavior - Indicates whether an instance stops or terminates when you initiate shutdown from the instance (using the operating system command for system shutdown).
      Returns:
      this
    • instanceName

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

      @Stability(Deprecated) @Deprecated public InstanceProps.Builder keyName(String 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
      Sets the value of InstanceProps.getKeyName()
      Parameters:
      keyName - Name of SSH keypair to grant access to instance.
      Returns:
      this
    • keyPair

      @Stability(Stable) public InstanceProps.Builder keyPair(IKeyPair keyPair)
      Sets the value of InstanceProps.getKeyPair()
      Parameters:
      keyPair - The SSH keypair to grant access to the instance.
      Returns:
      this
    • placementGroup

      @Stability(Stable) public InstanceProps.Builder placementGroup(IPlacementGroup placementGroup)
      Parameters:
      placementGroup - The placement group that you want to launch the instance into.
      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
    • ssmSessionPermissions

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

      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