Class Instance

All Implemented Interfaces:
IConstruct, IDependable, IResource, IConnectable, IInstance, IGrantable,, software.constructs.IConstruct

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:30:39.395Z") @Stability(Stable) public class Instance extends Resource implements IInstance
This represents a single EC2 instance.


 Vpc vpc;
 InstanceType instanceType;
 IMachineImage machineImage;
 Instance.Builder.create(this, "Instance")
         // ...
                 .build(), BlockDevice.builder()
  • Constructor Details

    • Instance

      protected Instance( objRef)
    • Instance

      protected Instance( initializationMode)
    • Instance

      @Stability(Stable) public Instance(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull InstanceProps props)
      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.

      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.

      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).

      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.