Class Instance

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.ec2.Instance
All Implemented Interfaces:
IResource, IConnectable, IInstance, IGrantable, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.97.0 (build 729de35)", date="2024-04-18T17:54:16.049Z") @Stability(Stable) public class Instance extends Resource implements IInstance
This represents a single 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));
 
  • Constructor Details

    • Instance

      protected Instance(software.amazon.jsii.JsiiObjectRef objRef)
    • Instance

      protected Instance(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Instance

      @Stability(Stable) public Instance(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull InstanceProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • addSecurityGroup

      @Stability(Stable) public void addSecurityGroup(@NotNull ISecurityGroup securityGroup)
      Add the security group to the instance.

      Parameters:
      securityGroup - : The security group to add. This parameter is required.
    • addToRolePolicy

      @Stability(Stable) public void addToRolePolicy(@NotNull PolicyStatement statement)
      Adds a statement to the IAM role assumed by the instance.

      Parameters:
      statement - This parameter is required.
    • addUserData

      @Stability(Stable) public void addUserData(@NotNull @NotNull String... commands)
      Add command to the startup script of the instance.

      The command must be in the scripting language supported by the instance's OS (i.e. Linux/Windows).

      Parameters:
      commands - This parameter is required.
    • getConnections

      @Stability(Stable) @NotNull public Connections getConnections()
      Allows specify security group connections for the instance.
      Specified by:
      getConnections in interface IConnectable
    • getGrantPrincipal

      @Stability(Stable) @NotNull public IPrincipal getGrantPrincipal()
      The principal to grant permissions to.
      Specified by:
      getGrantPrincipal in interface IGrantable
    • getInstance

      @Stability(Stable) @NotNull public CfnInstance getInstance()
      the underlying instance resource.
    • getInstanceAvailabilityZone

      @Stability(Stable) @NotNull public String getInstanceAvailabilityZone()
      The availability zone the instance was launched in.
      Specified by:
      getInstanceAvailabilityZone in interface IInstance
    • getInstanceId

      @Stability(Stable) @NotNull public String getInstanceId()
      The instance's ID.
      Specified by:
      getInstanceId in interface IInstance
    • getInstancePrivateDnsName

      @Stability(Stable) @NotNull public String getInstancePrivateDnsName()
      Private DNS name for this instance.
      Specified by:
      getInstancePrivateDnsName in interface IInstance
    • getInstancePrivateIp

      @Stability(Stable) @NotNull public String getInstancePrivateIp()
      Private IP for this instance.
      Specified by:
      getInstancePrivateIp in interface IInstance
    • getInstancePublicDnsName

      @Stability(Stable) @NotNull public String getInstancePublicDnsName()
      Publicly-routable DNS name for this instance.

      (May be an empty string if the instance does not have a public name).

      Specified by:
      getInstancePublicDnsName in interface IInstance
    • getInstancePublicIp

      @Stability(Stable) @NotNull public String getInstancePublicIp()
      Publicly-routable IP address for this instance.

      (May be an empty string if the instance does not have a public IP).

      Specified by:
      getInstancePublicIp in interface IInstance
    • getOsType

      @Stability(Stable) @NotNull public OperatingSystemType getOsType()
      The type of OS the instance is running.
    • getRole

      @Stability(Stable) @NotNull public IRole getRole()
      The IAM role assumed by the instance.
    • getUserData

      @Stability(Stable) @NotNull public UserData getUserData()
      UserData for the instance.