Class Instance_
This represents a single EC2 instance.
Inherited Members
Namespace: Amazon.CDK.AWS.EC2
Assembly: Amazon.CDK.Lib.dll
Syntax (csharp)
public class Instance_ : Resource, IInstance, IResource, IConnectable, IGrantable
Syntax (vb)
Public Class Instance_
Inherits Resource
Implements IInstance, IResource, IConnectable, IGrantable
Remarks
ExampleMetadata: infused
Examples
// Creates a distribution from an EC2 instance
Vpc vpc;
// Create an EC2 instance in a VPC. 'subnetType' can be private.
var instance = new Instance(this, "Instance", new InstanceProps {
Vpc = vpc,
InstanceType = InstanceType.Of(InstanceClass.BURSTABLE3, InstanceSize.MICRO),
MachineImage = MachineImage.LatestAmazonLinux2023(),
VpcSubnets = new SubnetSelection { SubnetType = SubnetType.PRIVATE_WITH_EGRESS }
});
new Distribution(this, "myDist", new DistributionProps {
DefaultBehavior = new BehaviorOptions { Origin = VpcOrigin.WithEc2Instance(instance) }
});
Synopsis
Constructors
Instance_(By |
Used by jsii to construct an instance of this class from a Javascript-owned object reference |
Instance_(Deputy |
Used by jsii to construct an instance of this class from DeputyProps |
Instance_(Construct, String, IInstance |
Properties
Connections | Allows specify security group connections for the instance. |
Grant |
The principal to grant permissions to. |
Instance | the underlying instance resource. |
Instance |
The availability zone the instance was launched in. |
Instance |
The instance's ID. |
Instance |
Private DNS name for this instance. |
Instance |
Private IP for this instance. |
Instance |
Publicly-routable DNS name for this instance. |
Instance |
Publicly-routable IP address for this instance. |
Os |
The type of OS the instance is running. |
Role | The IAM role assumed by the instance. |
User |
UserData for the instance. |
Methods
Add |
Add the security group to the instance. |
Add |
Adds a statement to the IAM role assumed by the instance. |
Add |
Add command to the startup script of the instance. |
Apply |
Use a CloudFormation Init configuration at instance startup. |
Constructors
Instance_(ByRefValue)
Used by jsii to construct an instance of this class from a Javascript-owned object reference
protected Instance_(ByRefValue reference)
Parameters
- reference Amazon.
JSII. Runtime. Deputy. By Ref Value The Javascript-owned object reference
Instance_(DeputyBase.DeputyProps)
Used by jsii to construct an instance of this class from DeputyProps
protected Instance_(DeputyBase.DeputyProps props)
Parameters
- props Amazon.
JSII. Runtime. Deputy. Deputy Base. Deputy Props The deputy props
Instance_(Construct, String, IInstanceProps)
public Instance_(Construct scope, string id, IInstanceProps props)
Parameters
- scope Constructs.
Construct - id System.
String - props IInstance
Props
Properties
Connections
Allows specify security group connections for the instance.
public virtual Connections_ Connections { get; }
Property Value
GrantPrincipal
The principal to grant permissions to.
public virtual IPrincipal GrantPrincipal { get; }
Property Value
Instance
the underlying instance resource.
public virtual CfnInstance Instance { get; }
Property Value
InstanceAvailabilityZone
The availability zone the instance was launched in.
public virtual string InstanceAvailabilityZone { get; }
Property Value
System.
Remarks
Attribute: true
InstanceId
The instance's ID.
public virtual string InstanceId { get; }
Property Value
System.
Remarks
Attribute: true
InstancePrivateDnsName
Private DNS name for this instance.
public virtual string InstancePrivateDnsName { get; }
Property Value
System.
Remarks
Attribute: true
InstancePrivateIp
Private IP for this instance.
public virtual string InstancePrivateIp { get; }
Property Value
System.
Remarks
Attribute: true
InstancePublicDnsName
Publicly-routable DNS name for this instance.
public virtual string InstancePublicDnsName { get; }
Property Value
System.
Remarks
(May be an empty string if the instance does not have a public name).
Attribute: true
InstancePublicIp
Publicly-routable IP address for this instance.
public virtual string InstancePublicIp { get; }
Property Value
System.
Remarks
(May be an empty string if the instance does not have a public IP).
Attribute: true
OsType
The type of OS the instance is running.
public virtual OperatingSystemType OsType { get; }
Property Value
Role
UserData
Methods
AddSecurityGroup(ISecurityGroup)
Add the security group to the instance.
public virtual void AddSecurityGroup(ISecurityGroup securityGroup)
Parameters
- securityGroup ISecurity
Group : The security group to add.
AddToRolePolicy(PolicyStatement)
Adds a statement to the IAM role assumed by the instance.
public virtual void AddToRolePolicy(PolicyStatement statement)
Parameters
- statement Policy
Statement
AddUserData(String[])
Add command to the startup script of the instance.
public virtual void AddUserData(params string[] commands)
Parameters
- commands System.
String []
Remarks
The command must be in the scripting language supported by the instance's OS (i.e. Linux/Windows).
ApplyCloudFormationInit(CloudFormationInit, IApplyCloudFormationInitOptions)
Use a CloudFormation Init configuration at instance startup.
public virtual void ApplyCloudFormationInit(CloudFormationInit init, IApplyCloudFormationInitOptions options = null)
Parameters
- init Cloud
Formation Init - options IApply
Cloud Formation Init Options
Remarks
This does the following: