Subnet

class aws_cdk.aws_ec2.Subnet(scope, id, *, availability_zone, cidr_block, vpc_id, map_public_ip_on_launch=None)

Bases: aws_cdk.core.Resource

Represents a new VPC subnet resource.

resource: :resource:: AWS::EC2::Subnet

__init__(scope, id, *, availability_zone, cidr_block, vpc_id, map_public_ip_on_launch=None)
Parameters
  • scope (Construct) –

  • id (str) –

  • props

  • availability_zone (str) – The availability zone for the subnet.

  • cidr_block (str) – The CIDR notation for this subnet.

  • vpc_id (str) – The VPC which this subnet is part of.

  • map_public_ip_on_launch (Optional[bool]) – Controls if a public IP is associated to an instance at launch. Default: true in Subnet.Public, false in Subnet.Private or Subnet.Isolated.

Return type

None

Methods

add_default_internet_route(gateway_id, gateway_attachment)

Create a default route that points to a passed IGW, with a dependency on the IGW’s attachment to the VPC.

Parameters
  • gateway_id (str) – the logical ID (ref) of the gateway attached to your VPC.

  • gateway_attachment (IDependable) – the gateway attachment construct to be added as a dependency.

Return type

None

add_default_nat_route(nat_gateway_id)

Adds an entry to this subnets route table that points to the passed NATGatwayId.

Parameters

nat_gateway_id (str) – The ID of the NAT gateway.

Return type

None

add_route(id, *, router_id, router_type, destination_cidr_block=None, destination_ipv6_cidr_block=None, enables_internet_connectivity=None)

Adds an entry to this subnets route table.

Parameters
  • id (str) –

  • options

  • router_id (str) – The ID of the router. Can be an instance ID, gateway ID, etc, depending on the router type.

  • router_type (RouterType) – What type of router to route this traffic to.

  • destination_cidr_block (Optional[str]) – IPv4 range this route applies to. Default: ‘0.0.0.0/0’

  • destination_ipv6_cidr_block (Optional[str]) – IPv6 range this route applies to. Default: - Uses IPv6

  • enables_internet_connectivity (Optional[bool]) – Whether this route will enable internet connectivity. If true, this route will be added before any AWS resources that depend on internet connectivity in the VPC will be created. Default: false

Return type

None

associate_network_acl(id, network_acl)

Associate a Network ACL with this subnet.

Parameters
Return type

None

to_string()

Returns a string representation of this construct.

Return type

str

Attributes

availability_zone

The Availability Zone the subnet is located in.

Return type

str

dependency_elements

Parts of this VPC subnet.

Return type

List[IDependable]

internet_connectivity_established

Dependable that can be depended upon to force internet connectivity established on the VPC.

Return type

IDependable

network_acl

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 explic it ALLOW entries that you add by creating a NetworkAcl object and calling associateNetworkAcl().

Return type

INetworkAcl

node

Construct tree node which offers APIs for interacting with the construct tree.

Return type

ConstructNode

route_table

The routeTableId attached to this subnet.

Return type

IRouteTable

stack

The stack in which this resource is defined.

Return type

Stack

subnet_availability_zone

attribute: :attribute:: true

Return type

str

subnet_id

The subnetId for this particular subnet.

Return type

str

subnet_ipv6_cidr_blocks

attribute: :attribute:: true

Return type

List[str]

subnet_network_acl_association_id

attribute: :attribute:: true

Return type

str

subnet_vpc_id

attribute: :attribute:: true

Return type

str

Static Methods

classmethod from_subnet_attributes(scope, id, *, availability_zone, subnet_id, route_table_id=None)
Parameters
  • scope (Construct) –

  • id (str) –

  • attrs

  • availability_zone (str) – The Availability Zone the subnet is located in.

  • subnet_id (str) – The subnetId for this particular subnet.

  • route_table_id (Optional[str]) – The ID of the route table for this particular subnet.

Return type

ISubnet

classmethod is_construct(x)

Return whether the given object is a Construct.

Parameters

x (Any) –

Return type

bool

classmethod is_vpc_subnet(x)
Parameters

x (Any) –

Return type

bool