Class Subnet

java.lang.Object
software.amazon.jsii.JsiiObject
software.constructs.Construct
software.amazon.awscdk.Resource
software.amazon.awscdk.services.ec2.Subnet
All Implemented Interfaces:
IResource, ISubnet, software.amazon.jsii.JsiiSerializable, software.constructs.IConstruct, software.constructs.IDependable
Direct Known Subclasses:
PrivateSubnet, PublicSubnet

@Generated(value="jsii-pacmak/1.98.0 (build 00b106d)", date="2024-05-08T21:35:06.247Z") @Stability(Stable) public class Subnet extends Resource implements ISubnet
Represents a new VPC subnet resource.

Example:

 Cluster cluster;
 ApplicationLoadBalancedFargateService loadBalancedFargateService = ApplicationLoadBalancedFargateService.Builder.create(this, "Service")
         .cluster(cluster)
         .memoryLimitMiB(1024)
         .desiredCount(1)
         .cpu(512)
         .taskImageOptions(ApplicationLoadBalancedTaskImageOptions.builder()
                 .image(ContainerImage.fromRegistry("amazon/amazon-ecs-sample"))
                 .build())
         .taskSubnets(SubnetSelection.builder()
                 .subnets(List.of(Subnet.fromSubnetId(this, "subnet", "VpcISOLATEDSubnet1Subnet80F07FA0")))
                 .build())
         .build();
 
  • Constructor Details

    • Subnet

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

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

      @Stability(Stable) public Subnet(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull SubnetProps props)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      props - This parameter is required.
  • Method Details

    • fromSubnetAttributes

      @Stability(Stable) @NotNull public static ISubnet fromSubnetAttributes(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull SubnetAttributes attrs)
      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      attrs - This parameter is required.
    • fromSubnetId

      @Stability(Stable) @NotNull public static ISubnet fromSubnetId(@NotNull software.constructs.Construct scope, @NotNull String id, @NotNull String subnetId)
      Import existing subnet from id.

      Parameters:
      scope - This parameter is required.
      id - This parameter is required.
      subnetId - This parameter is required.
    • isVpcSubnet

      @Stability(Stable) @NotNull public static Boolean isVpcSubnet(@NotNull Object x)
      Parameters:
      x - This parameter is required.
    • addDefaultInternetRoute

      @Stability(Stable) public void addDefaultInternetRoute(@NotNull String gatewayId, @NotNull software.constructs.IDependable gatewayAttachment)
      Create a default route that points to a passed IGW, with a dependency on the IGW's attachment to the VPC.

      Parameters:
      gatewayId - the logical ID (ref) of the gateway attached to your VPC. This parameter is required.
      gatewayAttachment - the gateway attachment construct to be added as a dependency. This parameter is required.
    • addDefaultNatRoute

      @Stability(Stable) public void addDefaultNatRoute(@NotNull String natGatewayId)
      Adds an entry to this subnets route table that points to the passed NATGatewayId.

      Parameters:
      natGatewayId - The ID of the NAT gateway. This parameter is required.
    • addIpv6DefaultEgressOnlyInternetRoute

      @Stability(Stable) public void addIpv6DefaultEgressOnlyInternetRoute(@NotNull String gatewayId)
      Create a default IPv6 route that points to a passed EIGW.

      Parameters:
      gatewayId - the logical ID (ref) of the gateway attached to your VPC. This parameter is required.
    • addIpv6DefaultInternetRoute

      @Stability(Stable) public void addIpv6DefaultInternetRoute(@NotNull String gatewayId)
      Create a default IPv6 route that points to a passed IGW.

      Parameters:
      gatewayId - the logical ID (ref) of the gateway attached to your VPC. This parameter is required.
    • addIpv6Nat64Route

      @Stability(Stable) public void addIpv6Nat64Route(@NotNull String natGatewayId)
      Adds an entry to this subnets route table that points to the passed NATGatewayId.

      Uses the known 64:ff9b::/96 prefix.

      Parameters:
      natGatewayId - The ID of the NAT gateway. This parameter is required.
    • addRoute

      @Stability(Stable) public void addRoute(@NotNull String id, @NotNull AddRouteOptions options)
      Adds an entry to this subnets route table.

      Parameters:
      id - This parameter is required.
      options - This parameter is required.
    • associateNetworkAcl

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

      Specified by:
      associateNetworkAcl in interface ISubnet
      Parameters:
      id - This parameter is required.
      networkAcl - This parameter is required.
    • getAvailabilityZone

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

      @Stability(Stable) @NotNull public List<software.constructs.IDependable> getDependencyElements()
      Parts of this VPC subnet.
    • getInternetConnectivityEstablished

      @Stability(Stable) @NotNull public software.constructs.IDependable getInternetConnectivityEstablished()
      Dependable that can be depended upon to force internet connectivity established on the VPC.
      Specified by:
      getInternetConnectivityEstablished in interface ISubnet
    • getIpv4CidrBlock

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

      @Stability(Stable) @NotNull public INetworkAcl getNetworkAcl()
      Network ACL associated with this Subnet.

      Upon creation, this is the default ACL which allows all traffic, except explicit DENY entries that you add.

      You can replace it with a custom ACL which denies all traffic except the explicit ALLOW entries that you add by creating a NetworkAcl object and calling associateNetworkAcl().

    • getRouteTable

      @Stability(Stable) @NotNull public IRouteTable getRouteTable()
      The routeTableId attached to this subnet.
      Specified by:
      getRouteTable in interface ISubnet
    • getSubnetAvailabilityZone

      @Stability(Stable) @NotNull public String getSubnetAvailabilityZone()
    • getSubnetId

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

      @Stability(Stable) @NotNull public List<String> getSubnetIpv6CidrBlocks()
    • getSubnetNetworkAclAssociationId

      @Stability(Stable) @NotNull public String getSubnetNetworkAclAssociationId()
    • getSubnetOutpostArn

      @Stability(Stable) @NotNull public String getSubnetOutpostArn()
      The Amazon Resource Name (ARN) of the Outpost for this subnet (if one exists).
    • getSubnetVpcId

      @Stability(Stable) @NotNull public String getSubnetVpcId()