Interface InstanceProps

All Superinterfaces:
software.amazon.jsii.JsiiSerializable
All Known Implementing Classes:
InstanceProps.Jsii$Proxy

@Generated(value="jsii-pacmak/1.97.0 (build 729de35)", date="2024-04-24T21:00:28.898Z") @Stability(Stable) public interface InstanceProps extends software.amazon.jsii.JsiiSerializable
Properties of an EC2 Instance.

Example:

 IVpc vpc;
 LoadBalancer lb = LoadBalancer.Builder.create(this, "LB")
         .vpc(vpc)
         .internetFacing(true)
         .build();
 // instance to add as the target for load balancer.
 Instance instance = Instance.Builder.create(this, "targetInstance")
         .vpc(vpc)
         .instanceType(InstanceType.of(InstanceClass.BURSTABLE2, InstanceSize.MICRO))
         .machineImage(AmazonLinuxImage.Builder.create().generation(AmazonLinuxGeneration.AMAZON_LINUX_2).build())
         .build();
 lb.addTarget(new InstanceTarget(instance));
 
  • Method Details

    • getInstanceType

      @Stability(Stable) @NotNull InstanceType getInstanceType()
      Type of instance to launch.
    • getMachineImage

      @Stability(Stable) @NotNull IMachineImage getMachineImage()
      AMI to launch.
    • getVpc

      @Stability(Stable) @NotNull IVpc getVpc()
      VPC to launch the instance in.
    • getAllowAllIpv6Outbound

      @Stability(Stable) @Nullable default Boolean getAllowAllIpv6Outbound()
      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

    • getAllowAllOutbound

      @Stability(Stable) @Nullable default Boolean getAllowAllOutbound()
      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

    • getAssociatePublicIpAddress

      @Stability(Stable) @Nullable default Boolean getAssociatePublicIpAddress()
      Whether to associate a public IP address to the primary network interface attached to this instance.

      Default: - public IP address is automatically assigned based on default behavior

    • getAvailabilityZone

      @Stability(Stable) @Nullable default String getAvailabilityZone()
      In which AZ to place the instance within the VPC.

      Default: - Random zone.

    • getBlockDevices

      @Stability(Stable) @Nullable default List<BlockDevice> getBlockDevices()
      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 Also:
    • getCreditSpecification

      @Stability(Stable) @Nullable default CpuCredits getCreditSpecification()
      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.

    • getDetailedMonitoring

      @Stability(Stable) @Nullable default Boolean getDetailedMonitoring()
      Whether "Detailed Monitoring" is enabled for this instance Keep in mind that Detailed Monitoring results in extra charges.

      Default: - false

      See Also:
    • getInit

      @Stability(Stable) @Nullable default CloudFormationInit getInit()
      Apply the given CloudFormation Init configuration to the instance at startup.

      Default: - no CloudFormation init

    • getInitOptions

      @Stability(Stable) @Nullable default ApplyCloudFormationInitOptions getInitOptions()
      Use the given options for applying CloudFormation Init.

      Describes the configsets to use and the timeout to wait

      Default: - default options

    • getInstanceName

      @Stability(Stable) @Nullable default String getInstanceName()
      The name of the instance.

      Default: - CDK generated name

    • getKeyName

      @Stability(Deprecated) @Deprecated @Nullable default String getKeyName()
      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.

    • getKeyPair

      @Stability(Stable) @Nullable default IKeyPair getKeyPair()
      The SSH keypair to grant access to the instance.

      Default: - No SSH access will be possible.

    • getPrivateIpAddress

      @Stability(Stable) @Nullable default String getPrivateIpAddress()
      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

    • getPropagateTagsToVolumeOnCreation

      @Stability(Stable) @Nullable default Boolean getPropagateTagsToVolumeOnCreation()
      Propagate the EC2 instance tags to the EBS volumes.

      Default: - false

    • getRequireImdsv2

      @Stability(Stable) @Nullable default Boolean getRequireImdsv2()
      Whether IMDSv2 should be required on this instance.

      Default: - false

    • getResourceSignalTimeout

      @Stability(Stable) @Nullable default Duration getResourceSignalTimeout()
      The length of time to wait for the resourceSignalCount.

      The maximum value is 43200 (12 hours).

      Default: Duration.minutes(5)

    • getRole

      @Stability(Stable) @Nullable default IRole getRole()
      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();
       
    • getSecurityGroup

      @Stability(Stable) @Nullable default ISecurityGroup getSecurityGroup()
      Security Group to assign to this instance.

      Default: - create new security group

    • getSourceDestCheck

      @Stability(Stable) @Nullable default Boolean getSourceDestCheck()
      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

    • getSsmSessionPermissions

      @Stability(Stable) @Nullable default Boolean getSsmSessionPermissions()
      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

    • getUserData

      @Stability(Stable) @Nullable default UserData getUserData()
      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.

    • getUserDataCausesReplacement

      @Stability(Stable) @Nullable default Boolean getUserDataCausesReplacement()
      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.

    • getVpcSubnets

      @Stability(Stable) @Nullable default SubnetSelection getVpcSubnets()
      Where to place the instance within the VPC.

      Default: - Private subnets.

    • builder

      @Stability(Stable) static InstanceProps.Builder builder()
      Returns:
      a InstanceProps.Builder of InstanceProps