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,ISubnetRef,software.amazon.jsii.JsiiSerializable,software.constructs.IConstruct,software.constructs.IDependable
- Direct Known Subclasses:
PrivateSubnet,PublicSubnet
@Generated(value="jsii-pacmak/1.116.0 (build 0eddcff)",
date="2025-10-29T11:15:38.264Z")
@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())
.minHealthyPercent(100)
.taskSubnets(SubnetSelection.builder()
.subnets(List.of(Subnet.fromSubnetId(this, "subnet", "VpcISOLATEDSubnet1Subnet80F07FA0")))
.build())
.build();
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class software.amazon.jsii.JsiiObject
software.amazon.jsii.JsiiObject.InitializationModeNested classes/interfaces inherited from interface software.constructs.IConstruct
software.constructs.IConstruct.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.IResource
IResource.Jsii$DefaultNested classes/interfaces inherited from interface software.amazon.awscdk.services.ec2.ISubnet
ISubnet.Jsii$Default, ISubnet.Jsii$Proxy -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSubnet(software.amazon.jsii.JsiiObject.InitializationMode initializationMode) protectedSubnet(software.amazon.jsii.JsiiObjectRef objRef) Subnet(software.constructs.Construct scope, String id, SubnetProps props) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDefaultInternetRoute(String gatewayId, 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.voidaddDefaultNatRoute(String natGatewayId) Adds an entry to this subnets route table that points to the passed NATGatewayId.voidaddIpv6DefaultEgressOnlyInternetRoute(String gatewayId) Create a default IPv6 route that points to a passed EIGW.voidaddIpv6DefaultInternetRoute(String gatewayId) Create a default IPv6 route that points to a passed IGW.voidaddIpv6Nat64Route(String natGatewayId) Adds an entry to this subnets route table that points to the passed NATGatewayId.voidaddRoute(String id, AddRouteOptions options) Adds an entry to this subnets route table.voidassociateNetworkAcl(String id, INetworkAcl networkAcl) Associate a Network ACL with this subnet.static ISubnetfromSubnetAttributes(software.constructs.Construct scope, String id, SubnetAttributes attrs) static ISubnetfromSubnetId(software.constructs.Construct scope, String id, String subnetId) Import existing subnet from id.The Availability Zone the subnet is located in.List<software.constructs.IDependable> Parts of this VPC subnet.software.constructs.IDependableDependable that can be depended upon to force internet connectivity established on the VPC.The IPv4 CIDR block for this subnet.Network ACL associated with this Subnet.The routeTableId attached to this subnet.The subnetId for this particular subnet.The Amazon Resource Name (ARN) of the Outpost for this subnet (if one exists).A reference to a Subnet resource.static BooleanMethods inherited from class software.amazon.awscdk.Resource
applyRemovalPolicy, generatePhysicalName, getEnv, getPhysicalName, getResourceArnAttribute, getResourceNameAttribute, getStack, isOwnedResource, isResourceMethods inherited from class software.constructs.Construct
getNode, isConstruct, toStringMethods inherited from class software.amazon.jsii.JsiiObject
jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSetMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface software.amazon.awscdk.IResource
applyRemovalPolicy, getEnv, getStackMethods inherited from interface software.amazon.jsii.JsiiSerializable
$jsii$toJson
-
Field Details
-
PROPERTY_INJECTION_ID
Uniquely identifies this class.
-
-
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
- 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
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
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
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
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
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:
associateNetworkAclin interfaceISubnet- Parameters:
id- This parameter is required.networkAcl- This parameter is required.
-
getAvailabilityZone
The Availability Zone the subnet is located in.- Specified by:
getAvailabilityZonein interfaceISubnet
-
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:
getInternetConnectivityEstablishedin interfaceISubnet
-
getIpv4CidrBlock
The IPv4 CIDR block for this subnet.- Specified by:
getIpv4CidrBlockin interfaceISubnet
-
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
NetworkAclobject and callingassociateNetworkAcl(). -
getRouteTable
The routeTableId attached to this subnet.- Specified by:
getRouteTablein interfaceISubnet
-
getSubnetAvailabilityZone
-
getSubnetId
The subnetId for this particular subnet.- Specified by:
getSubnetIdin interfaceISubnet
-
getSubnetIpv6CidrBlocks
-
getSubnetNetworkAclAssociationId
-
getSubnetOutpostArn
The Amazon Resource Name (ARN) of the Outpost for this subnet (if one exists). -
getSubnetRef
A reference to a Subnet resource.- Specified by:
getSubnetRefin interfaceISubnetRef
-
getSubnetVpcId
-