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, IConstruct, IDependable, IConnectable, IGrantable
Syntax (vb)
Public Class Instance_ Inherits Resource Implements IInstance, IResource, IConstruct, IDependable, 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_(Construct, string, IInstanceProps) | This represents a single EC2 instance. |
Properties
Connections | Allows specify security group connections for the instance. |
GrantPrincipal | The principal to grant permissions to. |
Instance | the underlying instance resource. |
InstanceAvailabilityZone | The availability zone the instance was launched in. |
InstanceId | The instance's ID. |
InstancePrivateDnsName | Private DNS name for this instance. |
InstancePrivateIp | Private IP for this instance. |
InstancePublicDnsName | Publicly-routable DNS name for this instance. |
InstancePublicIp | Publicly-routable IP address for this instance. |
OsType | The type of OS the instance is running. |
PROPERTY_INJECTION_ID | Uniquely identifies this class. |
Role | The IAM role assumed by the instance. |
UserData | UserData for the instance. |
Methods
AddSecurityGroup(ISecurityGroup) | Add the security group to the instance. |
AddToRolePolicy(PolicyStatement) | Adds a statement to the IAM role assumed by the instance. |
AddUserData(params string[]) | Add command to the startup script of the instance. |
ApplyCloudFormationInit(CloudFormationInit, IApplyCloudFormationInitOptions?) | Use a CloudFormation Init configuration at instance startup. |
Constructors
Instance_(Construct, string, IInstanceProps)
This represents a single EC2 instance.
public Instance_(Construct scope, string id, IInstanceProps props)
Parameters
- scope Construct
- id string
- props IInstanceProps
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) }
});
Properties
Connections
Allows specify security group connections for the instance.
public virtual Connections_ Connections { get; }
Property Value
Remarks
ExampleMetadata: infused
GrantPrincipal
The principal to grant permissions to.
public virtual IPrincipal GrantPrincipal { get; }
Property Value
Remarks
ExampleMetadata: infused
Instance
the underlying instance resource.
public virtual CfnInstance Instance { get; }
Property Value
Remarks
ExampleMetadata: infused
InstanceAvailabilityZone
The availability zone the instance was launched in.
public virtual string InstanceAvailabilityZone { get; }
Property Value
Remarks
Attribute: true
InstanceId
The instance's ID.
public virtual string InstanceId { get; }
Property Value
Remarks
Attribute: true
InstancePrivateDnsName
Private DNS name for this instance.
public virtual string InstancePrivateDnsName { get; }
Property Value
Remarks
Attribute: true
InstancePrivateIp
Private IP for this instance.
public virtual string InstancePrivateIp { get; }
Property Value
Remarks
Attribute: true
InstancePublicDnsName
Publicly-routable DNS name for this instance.
public virtual string InstancePublicDnsName { get; }
Property Value
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
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
Remarks
ExampleMetadata: infused
PROPERTY_INJECTION_ID
Uniquely identifies this class.
public static string PROPERTY_INJECTION_ID { get; }
Property Value
Remarks
ExampleMetadata: infused
Role
The IAM role assumed by the instance.
public virtual IRole Role { get; }
Property Value
Remarks
ExampleMetadata: infused
UserData
UserData for the instance.
public virtual UserData UserData { get; }
Property Value
Remarks
ExampleMetadata: infused
Methods
AddSecurityGroup(ISecurityGroup)
Add the security group to the instance.
public virtual void AddSecurityGroup(ISecurityGroup securityGroup)
Parameters
- securityGroup ISecurityGroup
: The security group to add.
Remarks
ExampleMetadata: infused
AddToRolePolicy(PolicyStatement)
Adds a statement to the IAM role assumed by the instance.
public virtual void AddToRolePolicy(PolicyStatement statement)
Parameters
- statement PolicyStatement
Remarks
ExampleMetadata: infused
AddUserData(params string[])
Add command to the startup script of the instance.
public virtual void AddUserData(params string[] commands)
Parameters
- commands 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 CloudFormationInit
- options IApplyCloudFormationInitOptions
Remarks
This does the following: