PublicSubnet

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

Bases: aws_cdk.aws_ec2.Subnet

Represents a public VPC subnet resource.

Parameters
  • scope (Construct) –

  • id (str) –

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

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_nat_gateway()

Creates a new managed NAT gateway attached to this public subnet.

Also adds the EIP for the managed NAT.

return :rtype: CfnNatGateway :return: A ref to the the NAT Gateway ID

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

  • 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]

env

The environment this resource belongs to.

For resources that are created and managed by the CDK (generally, those created by creating new class instances like Role, Bucket, etc.), this is always the same as the environment of the stack they belong to; however, for imported resources (those obtained from static methods like fromRoleArn, fromBucketName, etc.), that might be different than the stack they were imported into.

Return type

ResourceEnvironment

internet_connectivity_established

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

Return type

IDependable

ipv4_cidr_block

The IPv4 CIDR block for this subnet.

attribute: :attribute:: true

Return type

str

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

The construct tree node associated with this construct.

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_public_subnet_attributes(scope, id, *, subnet_id, availability_zone=None, ipv4_cidr_block=None, route_table_id=None)
Parameters
  • scope (Construct) –

  • id (str) –

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

  • availability_zone (Optional[str]) – The Availability Zone the subnet is located in. Default: - No AZ information, cannot use AZ selection features

  • ipv4_cidr_block (Optional[str]) – The IPv4 CIDR block associated with the subnet. Default: - No CIDR information, cannot use CIDR filter features

  • route_table_id (Optional[str]) – The ID of the route table for this particular subnet. Default: - No route table information, cannot create VPC endpoints

Return type

IPublicSubnet

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

  • id (str) –

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

  • availability_zone (Optional[str]) – The Availability Zone the subnet is located in. Default: - No AZ information, cannot use AZ selection features

  • ipv4_cidr_block (Optional[str]) – The IPv4 CIDR block associated with the subnet. Default: - No CIDR information, cannot use CIDR filter features

  • route_table_id (Optional[str]) – The ID of the route table for this particular subnet. Default: - No route table information, cannot create VPC endpoints

Return type

ISubnet

classmethod from_subnet_id(scope, id, subnet_id)

Import existing subnet from id.

Parameters
  • scope (Construct) –

  • id (str) –

  • subnet_id (str) –

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