Class SubnetV2
(experimental) The SubnetV2 class represents a subnet within a VPC (Virtual Private Cloud) in AWS.
Inherited Members
Namespace: Amazon.CDK.AWS.ec2.Alpha
Assembly: Amazon.CDK.AWS.ec2.Alpha.dll
Syntax (csharp)
public class SubnetV2 : Resource, ISubnetV2, ISubnet, IResource, ISubnetRef, IConstruct, IDependable, IEnvironmentAware
Syntax (vb)
Public Class SubnetV2 Inherits Resource Implements ISubnetV2, ISubnet, IResource, ISubnetRef, IConstruct, IDependable, IEnvironmentAware
Remarks
It extends the Resource class and implements the ISubnet interface.
Instances of this class can be used to create and manage subnets within a VpcV2 instance. Subnets can be configured with specific IP address ranges (IPv4 and IPv6), availability zones, and subnet types (e.g., public, private, isolated).
Stability: Experimental
Resource: AWS::EC2::Subnet
ExampleMetadata: infused
Examples
var myVpc = new VpcV2(this, "Vpc");
var routeTable = new RouteTable(this, "RouteTable", new RouteTableProps {
Vpc = myVpc
});
var subnet = new SubnetV2(this, "Subnet", new SubnetV2Props {
Vpc = myVpc,
AvailabilityZone = "eu-west-2a",
Ipv4CidrBlock = new IpCidr("10.0.0.0/24"),
SubnetType = SubnetType.PRIVATE_ISOLATED
});
var natgw = new NatGateway(this, "NatGW", new NatGatewayProps {
Subnet = subnet,
Vpc = myVpc,
ConnectivityType = NatConnectivityType.PRIVATE,
PrivateIpAddress = "10.0.0.42"
});
new Route(this, "NatGwRoute", new RouteProps {
RouteTable = routeTable,
Destination = "0.0.0.0/0",
Target = new Dictionary<string, IRouteTarget?> { { "gateway", natgw } }
});
Synopsis
Constructors
| SubnetV2(Construct, string, ISubnetV2Props) | (experimental) Constructs a new SubnetV2 instance. |
Properties
| AvailabilityZone | (experimental) The Availability Zone the subnet is located in. |
| InternetConnectivityEstablished | (experimental) Dependencies for internet connectivity This Property exposes the RouteTable-Subnet association so that other resources can depend on it. |
| Ipv4CidrBlock | (experimental) The IPv4 CIDR block for this subnet. |
| Ipv6CidrBlock | (experimental) The IPv6 CIDR Block for this subnet. |
| NetworkAcl | (experimental) Returns the Network ACL associated with this subnet. |
| PROPERTY_INJECTION_ID | (experimental) Uniquely identifies this class. |
| RouteTable | (experimental) Return the Route Table associated with this subnet. |
| SubnetId | (experimental) The subnetId for this particular subnet. |
| SubnetRef | (experimental) A reference to a Subnet resource. |
| SubnetType | (experimental) The type of subnet (public or private) that this subnet represents. |
Methods
| AssociateNetworkAcl(string, INetworkAcl) | (experimental) Associate a Network ACL with this subnet. |
| FromSubnetV2Attributes(Construct, string, ISubnetV2Attributes) | (experimental) Import an existing subnet to the VPC. |
Constructors
SubnetV2(Construct, string, ISubnetV2Props)
(experimental) Constructs a new SubnetV2 instance.
public SubnetV2(Construct scope, string id, ISubnetV2Props props)
Parameters
- scope Construct
The parent Construct that this resource will be part of.
- id string
The unique identifier for this resource.
- props ISubnetV2Props
The configuration properties for the subnet.
Remarks
Stability: Experimental
Properties
AvailabilityZone
(experimental) The Availability Zone the subnet is located in.
public virtual string AvailabilityZone { get; }
Property Value
Remarks
Stability: Experimental
InternetConnectivityEstablished
(experimental) Dependencies for internet connectivity This Property exposes the RouteTable-Subnet association so that other resources can depend on it.
public virtual IDependable InternetConnectivityEstablished { get; }
Property Value
IDependable
Remarks
Stability: Experimental
Ipv4CidrBlock
(experimental) The IPv4 CIDR block for this subnet.
public virtual string Ipv4CidrBlock { get; }
Property Value
Remarks
Stability: Experimental
Ipv6CidrBlock
(experimental) The IPv6 CIDR Block for this subnet.
public virtual string? Ipv6CidrBlock { get; }
Property Value
Remarks
Stability: Experimental
NetworkAcl
(experimental) Returns the Network ACL associated with this subnet.
public virtual INetworkAcl NetworkAcl { get; }
Property Value
Remarks
Stability: Experimental
PROPERTY_INJECTION_ID
(experimental) Uniquely identifies this class.
public static string PROPERTY_INJECTION_ID { get; }
Property Value
Remarks
Stability: Experimental
RouteTable
(experimental) Return the Route Table associated with this subnet.
public virtual IRouteTable RouteTable { get; }
Property Value
Remarks
Stability: Experimental
SubnetId
(experimental) The subnetId for this particular subnet.
public virtual string SubnetId { get; }
Property Value
Remarks
Stability: Experimental
Attribute: true
SubnetRef
(experimental) A reference to a Subnet resource.
public virtual ISubnetReference SubnetRef { get; }
Property Value
Remarks
Stability: Experimental
SubnetType
(experimental) The type of subnet (public or private) that this subnet represents.
public virtual SubnetType? SubnetType { get; }
Property Value
Remarks
Stability: Experimental
Attribute: SubnetType
Methods
AssociateNetworkAcl(string, INetworkAcl)
(experimental) Associate a Network ACL with this subnet.
public virtual void AssociateNetworkAcl(string id, INetworkAcl networkAcl)
Parameters
- id string
The unique identifier for this association.
- networkAcl INetworkAcl
The Network ACL to associate with this subnet.
Remarks
Stability: Experimental
FromSubnetV2Attributes(Construct, string, ISubnetV2Attributes)
(experimental) Import an existing subnet to the VPC.
public static ISubnetV2 FromSubnetV2Attributes(Construct scope, string id, ISubnetV2Attributes attrs)
Parameters
- scope Construct
- id string
- attrs ISubnetV2Attributes
Returns
Remarks
Stability: Experimental