java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.ec2.alpha.SubnetV2
All Implemented Interfaces:
IResource, ISubnetV2, ISubnet, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable

@Generated(value="jsii-pacmak/1.104.0 (build e79254c)", date="2024-11-13T21:17:43.036Z") @Stability(Experimental) public class SubnetV2 extends Resource implements ISubnetV2
(experimental) The SubnetV2 class represents a subnet within a VPC (Virtual Private Cloud) in AWS.

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

Example:

 VpcV2 myVpc = new VpcV2(this, "Vpc");
 RouteTable routeTable = RouteTable.Builder.create(this, "RouteTable")
         .vpc(myVpc)
         .build();
 SubnetV2 subnet = SubnetV2.Builder.create(this, "Subnet")
         .vpc(myVpc)
         .availabilityZone("eu-west-2a")
         .ipv4CidrBlock(new IpCidr("10.0.0.0/24"))
         .subnetType(SubnetType.PRIVATE_ISOLATED)
         .build();
 NatGateway natgw = NatGateway.Builder.create(this, "NatGW")
         .subnet(subnet)
         .vpc(myVpc)
         .connectivityType(NatConnectivityType.PRIVATE)
         .privateIpAddress("10.0.0.42")
         .build();
 Route.Builder.create(this, "NatGwRoute")
         .routeTable(routeTable)
         .destination("0.0.0.0/0")
         .target(Map.of("gateway", natgw))
         .build();
 
  • Constructor Details

    • SubnetV2

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

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

      @Stability(Experimental) public SubnetV2(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull SubnetV2Props props)
      (experimental) Constructs a new SubnetV2 instance.

      Parameters:
      scope - The parent Construct that this resource will be part of. This parameter is required.
      id - The unique identifier for this resource. This parameter is required.
      props - The configuration properties for the subnet. This parameter is required.
  • Method Details

    • fromSubnetV2Attributes

      @Stability(Experimental) @NotNull public static ISubnetV2 fromSubnetV2Attributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull SubnetV2Attributes attrs)
      (experimental) Import an existing subnet to the VPC.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      attrs - This parameter is required.
    • associateNetworkAcl

      @Stability(Experimental) public void associateNetworkAcl(@NotNull String id, @NotNull INetworkAcl networkAcl)
      (experimental) Associate a Network ACL with this subnet.

      Specified by:
      associateNetworkAcl in interface ISubnet
      Parameters:
      id - The unique identifier for this association. This parameter is required.
      networkAcl - The Network ACL to associate with this subnet. This parameter is required.
    • getAvailabilityZone

      @Stability(Experimental) @NotNull public String getAvailabilityZone()
      (experimental) The Availability Zone the subnet is located in.
      Specified by:
      getAvailabilityZone in interface ISubnet
    • getInternetConnectivityEstablished

      @Stability(Experimental) @NotNull public software.constructs.IDependable getInternetConnectivityEstablished()
      (experimental) Dependencies for internet connectivity This Property exposes the RouteTable-Subnet association so that other resources can depend on it.
      Specified by:
      getInternetConnectivityEstablished in interface ISubnet
    • getIpv4CidrBlock

      @Stability(Experimental) @NotNull public String getIpv4CidrBlock()
      (experimental) The IPv4 CIDR block for this subnet.
      Specified by:
      getIpv4CidrBlock in interface ISubnet
    • getNetworkAcl

      @Stability(Experimental) @NotNull public INetworkAcl getNetworkAcl()
      (experimental) Returns the Network ACL associated with this subnet.
    • getRouteTable

      @Stability(Experimental) @NotNull public IRouteTable getRouteTable()
      (experimental) Return the Route Table associated with this subnet.
      Specified by:
      getRouteTable in interface ISubnet
    • getSubnetId

      @Stability(Experimental) @NotNull public String getSubnetId()
      (experimental) The subnetId for this particular subnet.
      Specified by:
      getSubnetId in interface ISubnet
    • getIpv6CidrBlock

      @Stability(Experimental) @Nullable public String getIpv6CidrBlock()
      (experimental) The IPv6 CIDR Block for this subnet.
      Specified by:
      getIpv6CidrBlock in interface ISubnetV2
    • getSubnetType

      @Stability(Experimental) @Nullable public SubnetType getSubnetType()
      (experimental) The type of subnet (public or private) that this subnet represents.
      Specified by:
      getSubnetType in interface ISubnetV2