Skip to main content

subnets

Creates, updates, deletes, gets or lists a subnets resource.

Overview

Namesubnets
TypeResource
Idaws.ec2.subnets

Fields

The following fields are returned by SELECT queries:

NameDatatypeDescription
assign_ipv_6_address_on_creationbooleanIndicates whether a network interface created in this subnet (including a network interface created by RunInstances) receives an IPv6 address.
availability_zonestringThe Availability Zone of the subnet.
availability_zone_idstringThe AZ ID of the subnet.
available_ip_address_countintegerThe number of unused private IPv4 addresses in the subnet. The IPv4 addresses for any stopped instances are considered unavailable.
block_public_access_statesstringThe state of VPC Block Public Access (BPA).
cidr_blockstringThe IPv4 CIDR block assigned to the subnet.
customer_owned_ipv_4_poolstringThe customer-owned IPv4 address pool associated with the subnet.
default_for_azbooleanIndicates whether this is the default subnet for the Availability Zone.
enable_dns_64booleanIndicates whether DNS queries made to the Amazon-provided DNS Resolver in this subnet should return synthetic IPv6 addresses for IPv4-only destinations.
enable_lni_at_device_indexintegerIndicates the device position for local network interfaces in this subnet. For example, 1 indicates local network interfaces in this subnet are the secondary network interface (eth1).
ipv_6_cidr_block_association_setstringInformation about the IPv6 CIDR blocks associated with the subnet.
ipv_6_nativebooleanIndicates whether this is an IPv6 only subnet.
map_customer_owned_ip_on_launchbooleanIndicates whether a network interface created in this subnet (including a network interface created by RunInstances) receives a customer-owned IPv4 address.
map_public_ip_on_launchbooleanIndicates whether instances launched in this subnet receive a public IPv4 address. Amazon Web Services charges for all public IPv4 addresses, including public IPv4 addresses associated with running instances and Elastic IP addresses. For more information, see the Public IPv4 Address tab on the Amazon VPC pricing page.
outpost_arnstringThe Amazon Resource Name (ARN) of the Outpost.
owner_idstringThe ID of the Amazon Web Services account that owns the subnet.
private_dns_name_options_on_launchstringThe type of hostnames to assign to instances in the subnet at launch. An instance hostname is based on the IPv4 address or ID of the instance.
statestringThe current state of the subnet. failed: The underlying infrastructure to support the subnet failed to provision as expected. failed-insufficient-capacity: The underlying infrastructure to support the subnet failed to provision due to a shortage of EC2 instance capacity.
subnet_arnstringThe Amazon Resource Name (ARN) of the subnet.
subnet_idstringThe ID of the subnet.
tagsstringAny tags assigned to the subnet.
typestringIndicates if this is a subnet used with Amazon Elastic VMware Service (EVS). Possible values are Elastic VMware Service or no value. For more information about Amazon EVS, see Amazon Elastic VMware Service API Reference .
vpc_idstringThe ID of the VPC the subnet is in.

Methods

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
describe_subnetsselectregionFilter, SubnetId, NextToken, MaxResults, DryRunDescribes your subnets. The default is to describe all your subnets. Alternatively, you can specify specific subnet IDs or filter the results to include only the subnets that match specific criteria. For more information, see Subnets in the Amazon VPC User Guide.
create_subnetinsertVpcId, regionTagSpecification, AvailabilityZone, AvailabilityZoneId, CidrBlock, Ipv6CidrBlock, OutpostArn, Ipv6Native, Ipv4IpamPoolId, Ipv4NetmaskLength, Ipv6IpamPoolId, Ipv6NetmaskLength, DryRunCreates a subnet in the specified VPC. For an IPv4 only subnet, specify an IPv4 CIDR block. If the VPC has an IPv6 CIDR block, you can create an IPv6 only subnet or a dual stack subnet instead. For an IPv6 only subnet, specify an IPv6 CIDR block. For a dual stack subnet, specify both an IPv4 CIDR block and an IPv6 CIDR block. A subnet CIDR block must not overlap the CIDR block of an existing subnet in the VPC. After you create a subnet, you can't change its CIDR block. The allowed size for an IPv4 subnet is between a /28 netmask (16 IP addresses) and a /16 netmask (65,536 IP addresses). Amazon Web Services reserves both the first four and the last IPv4 address in each subnet's CIDR block. They're not available for your use. If you've associated an IPv6 CIDR block with your VPC, you can associate an IPv6 CIDR block with a subnet when you create it. If you add more than one subnet to a VPC, they're set up in a star topology with a logical router in the middle. When you stop an instance in a subnet, it retains its private IPv4 address. It's therefore possible to have a subnet with no running instances (they're all stopped), but no remaining IP addresses available. For more information, see Subnets in the Amazon VPC User Guide.
create_default_subnetinsertregionAvailabilityZone, DryRun, Ipv6Native, AvailabilityZoneIdCreates a default subnet with a size /20 IPv4 CIDR block in the specified Availability Zone in your default VPC. You can have only one default subnet per Availability Zone. For more information, see Create a default subnet in the Amazon VPC User Guide.
associate_subnet_cidr_blockupdateSubnetId, regionIpv6IpamPoolId, Ipv6NetmaskLength, Ipv6CidrBlockAssociates a CIDR block with your subnet. You can only associate a single IPv6 CIDR block with your subnet.
disassociate_subnet_cidr_blockupdateAssociationId, regionDisassociates a CIDR block from a subnet. Currently, you can disassociate an IPv6 CIDR block only. You must detach or delete all gateways and resources that are associated with the CIDR block before you can disassociate it.
delete_subnetdeleteSubnetId, regionDryRunDeletes the specified subnet. You must terminate all running instances in the subnet before you can delete the subnet.
modify_subnet_attributeexecSubnetId, regionAssignIpv6AddressOnCreation, MapPublicIpOnLaunch, MapCustomerOwnedIpOnLaunch, CustomerOwnedIpv4Pool, EnableDns64, PrivateDnsHostnameTypeOnLaunch, EnableResourceNameDnsARecordOnLaunch, EnableResourceNameDnsAAAARecordOnLaunch, EnableLniAtDeviceIndex, DisableLniAtDeviceIndexModifies a subnet attribute. You can only modify one attribute at a time. Use this action to modify subnets on Amazon Web Services Outposts. To modify a subnet on an Outpost rack, set both MapCustomerOwnedIpOnLaunch and CustomerOwnedIpv4Pool. These two parameters act as a single attribute. To modify a subnet on an Outpost server, set either EnableLniAtDeviceIndex or DisableLniAtDeviceIndex. For more information about Amazon Web Services Outposts, see the following: Outpost servers Outpost racks

Parameters

Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.

NameDatatypeDescription
AssociationIdstringThe association ID for the CIDR block.
SubnetIdstringThe ID of the subnet.
VpcIdstringThe ID of the VPC.
regionstringAWS region (default: us-east-1)
AssignIpv6AddressOnCreationobjectSpecify true to indicate that network interfaces created in the specified subnet should be assigned an IPv6 address. This includes a network interface that's created when launching an instance into the subnet (the instance therefore receives an IPv6 address). If you enable the IPv6 addressing feature for your subnet, your network interface or instance only receives an IPv6 address if it's created using version 2016-11-15 or later of the Amazon EC2 API.
AvailabilityZonestringThe Availability Zone in which to create the default subnet. Either AvailabilityZone or AvailabilityZoneId must be specified, but not both.
AvailabilityZoneIdstringThe ID of the Availability Zone. Either AvailabilityZone or AvailabilityZoneId must be specified, but not both.
CidrBlockstringThe IPv4 network range for the subnet, in CIDR notation. For example, 10.0.0.0/24. We modify the specified CIDR block to its canonical form; for example, if you specify 100.68.0.18/18, we modify it to 100.68.0.0/18. This parameter is not supported for an IPv6 only subnet.
CustomerOwnedIpv4PoolstringThe customer-owned IPv4 address pool associated with the subnet. You must set this value when you specify true for MapCustomerOwnedIpOnLaunch.
DisableLniAtDeviceIndexobjectSpecify true to indicate that local network interfaces at the current position should be disabled.
DryRunbooleanChecks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.
EnableDns64objectIndicates whether DNS queries made to the Amazon-provided DNS Resolver in this subnet should return synthetic IPv6 addresses for IPv4-only destinations. You must first configure a NAT gateway in a public subnet (separate from the subnet containing the IPv6-only workloads). For example, the subnet containing the NAT gateway should have a 0.0.0.0/0 route pointing to the internet gateway. For more information, see Configure DNS64 and NAT64 in the Amazon VPC User Guide.
EnableLniAtDeviceIndexintegerIndicates the device position for local network interfaces in this subnet. For example, 1 indicates local network interfaces in this subnet are the secondary network interface (eth1). A local network interface cannot be the primary network interface (eth0).
EnableResourceNameDnsAAAARecordOnLaunchobjectIndicates whether to respond to DNS queries for instance hostnames with DNS AAAA records.
EnableResourceNameDnsARecordOnLaunchobjectIndicates whether to respond to DNS queries for instance hostnames with DNS A records.
FilterarrayThe filters. availability-zone - The Availability Zone for the subnet. You can also use availabilityZone as the filter name. availability-zone-id - The ID of the Availability Zone for the subnet. You can also use availabilityZoneId as the filter name. available-ip-address-count - The number of IPv4 addresses in the subnet that are available. cidr-block - The IPv4 CIDR block of the subnet. The CIDR block you specify must exactly match the subnet's CIDR block for information to be returned for the subnet. You can also use cidr or cidrBlock as the filter names. customer-owned-ipv4-pool - The customer-owned IPv4 address pool associated with the subnet. default-for-az - Indicates whether this is the default subnet for the Availability Zone (true | false). You can also use defaultForAz as the filter name. enable-dns64 - Indicates whether DNS queries made to the Amazon-provided DNS Resolver in this subnet should return synthetic IPv6 addresses for IPv4-only destinations. enable-lni-at-device-index - Indicates the device position for local network interfaces in this subnet. For example, 1 indicates local network interfaces in this subnet are the secondary network interface (eth1). ipv6-cidr-block-association.ipv6-cidr-block - An IPv6 CIDR block associated with the subnet. ipv6-cidr-block-association.association-id - An association ID for an IPv6 CIDR block associated with the subnet. ipv6-cidr-block-association.state - The state of an IPv6 CIDR block associated with the subnet. ipv6-native - Indicates whether this is an IPv6 only subnet (true | false). map-customer-owned-ip-on-launch - Indicates whether a network interface created in this subnet (including a network interface created by RunInstances) receives a customer-owned IPv4 address. map-public-ip-on-launch - Indicates whether instances launched in this subnet receive a public IPv4 address. outpost-arn - The Amazon Resource Name (ARN) of the Outpost. owner-id - The ID of the Amazon Web Services account that owns the subnet. private-dns-name-options-on-launch.hostname-type - The type of hostname to assign to instances in the subnet at launch. For IPv4-only and dual-stack (IPv4 and IPv6) subnets, an instance DNS name can be based on the instance IPv4 address (ip-name) or the instance ID (resource-name). For IPv6 only subnets, an instance DNS name must be based on the instance ID (resource-name). private-dns-name-options-on-launch.enable-resource-name-dns-a-record - Indicates whether to respond to DNS queries for instance hostnames with DNS A records. private-dns-name-options-on-launch.enable-resource-name-dns-aaaa-record - Indicates whether to respond to DNS queries for instance hostnames with DNS AAAA records. state - The state of the subnet (pending | available). subnet-arn - The Amazon Resource Name (ARN) of the subnet. subnet-id - The ID of the subnet. tag - The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key Owner and the value TeamA, specify tag:Owner for the filter name and TeamA for the filter value. tag-key - The key of a tag assigned to the resource. Use this filter to find all resources assigned a tag with a specific key, regardless of the tag value. vpc-id - The ID of the VPC for the subnet.
Ipv4IpamPoolIdstringAn IPv4 IPAM pool ID for the subnet.
Ipv4NetmaskLengthintegerAn IPv4 netmask length for the subnet.
Ipv6CidrBlockstringThe IPv6 CIDR block for your subnet.
Ipv6IpamPoolIdstringAn IPv6 IPAM pool ID.
Ipv6NativebooleanIndicates whether to create an IPv6 only subnet. If you already have a default subnet for this Availability Zone, you must delete it before you can create an IPv6 only subnet.
Ipv6NetmaskLengthintegerAn IPv6 netmask length.
MapCustomerOwnedIpOnLaunchobjectSpecify true to indicate that network interfaces attached to instances created in the specified subnet should be assigned a customer-owned IPv4 address. When this value is true, you must specify the customer-owned IP pool using CustomerOwnedIpv4Pool.
MapPublicIpOnLaunchobjectSpecify true to indicate that network interfaces attached to instances created in the specified subnet should be assigned a public IPv4 address. Amazon Web Services charges for all public IPv4 addresses, including public IPv4 addresses associated with running instances and Elastic IP addresses. For more information, see the Public IPv4 Address tab on the Amazon VPC pricing page.
MaxResultsintegerThe maximum number of items to return for this request. To get the next page of items, make another request with the token returned in the output. For more information, see Pagination.
NextTokenstringThe token returned from a previous paginated request. Pagination continues from the end of the items returned by the previous request.
OutpostArnstringThe Amazon Resource Name (ARN) of the Outpost. If you specify an Outpost ARN, you must also specify the Availability Zone of the Outpost subnet.
PrivateDnsHostnameTypeOnLaunchstringThe type of hostname to assign to instances in the subnet at launch. For IPv4-only and dual-stack (IPv4 and IPv6) subnets, an instance DNS name can be based on the instance IPv4 address (ip-name) or the instance ID (resource-name). For IPv6 only subnets, an instance DNS name must be based on the instance ID (resource-name).
SubnetIdarrayThe IDs of the subnets. Default: Describes all your subnets.
TagSpecificationarrayThe tags to assign to the subnet.

SELECT examples

Describes your subnets. The default is to describe all your subnets. Alternatively, you can specify specific subnet IDs or filter the results to include only the subnets that match specific criteria. For more information, see Subnets in the Amazon VPC User Guide.

SELECT
assign_ipv_6_address_on_creation,
availability_zone,
availability_zone_id,
available_ip_address_count,
block_public_access_states,
cidr_block,
customer_owned_ipv_4_pool,
default_for_az,
enable_dns_64,
enable_lni_at_device_index,
ipv_6_cidr_block_association_set,
ipv_6_native,
map_customer_owned_ip_on_launch,
map_public_ip_on_launch,
outpost_arn,
owner_id,
private_dns_name_options_on_launch,
state,
subnet_arn,
subnet_id,
tags,
type,
vpc_id
FROM aws.ec2.subnets
WHERE region = '{{ region }}' -- required
AND Filter = '{{ Filter }}'
AND SubnetId = '{{ SubnetId }}'
AND NextToken = '{{ NextToken }}'
AND MaxResults = '{{ MaxResults }}'
AND DryRun = '{{ DryRun }}'
;

INSERT examples

Creates a subnet in the specified VPC. For an IPv4 only subnet, specify an IPv4 CIDR block. If the VPC has an IPv6 CIDR block, you can create an IPv6 only subnet or a dual stack subnet instead. For an IPv6 only subnet, specify an IPv6 CIDR block. For a dual stack subnet, specify both an IPv4 CIDR block and an IPv6 CIDR block. A subnet CIDR block must not overlap the CIDR block of an existing subnet in the VPC. After you create a subnet, you can't change its CIDR block. The allowed size for an IPv4 subnet is between a /28 netmask (16 IP addresses) and a /16 netmask (65,536 IP addresses). Amazon Web Services reserves both the first four and the last IPv4 address in each subnet's CIDR block. They're not available for your use. If you've associated an IPv6 CIDR block with your VPC, you can associate an IPv6 CIDR block with a subnet when you create it. If you add more than one subnet to a VPC, they're set up in a star topology with a logical router in the middle. When you stop an instance in a subnet, it retains its private IPv4 address. It's therefore possible to have a subnet with no running instances (they're all stopped), but no remaining IP addresses available. For more information, see Subnets in the Amazon VPC User Guide.

INSERT INTO aws.ec2.subnets (
VpcId,
region,
TagSpecification,
AvailabilityZone,
AvailabilityZoneId,
CidrBlock,
Ipv6CidrBlock,
OutpostArn,
Ipv6Native,
Ipv4IpamPoolId,
Ipv4NetmaskLength,
Ipv6IpamPoolId,
Ipv6NetmaskLength,
DryRun
)
SELECT
'{{ VpcId }}',
'{{ region }}',
'{{ TagSpecification }}',
'{{ AvailabilityZone }}',
'{{ AvailabilityZoneId }}',
'{{ CidrBlock }}',
'{{ Ipv6CidrBlock }}',
'{{ OutpostArn }}',
'{{ Ipv6Native }}',
'{{ Ipv4IpamPoolId }}',
'{{ Ipv4NetmaskLength }}',
'{{ Ipv6IpamPoolId }}',
'{{ Ipv6NetmaskLength }}',
'{{ DryRun }}'
RETURNING
assign_ipv_6_address_on_creation,
availability_zone,
availability_zone_id,
available_ip_address_count,
block_public_access_states,
cidr_block,
customer_owned_ipv_4_pool,
default_for_az,
enable_dns_64,
enable_lni_at_device_index,
ipv_6_cidr_block_association_set,
ipv_6_native,
map_customer_owned_ip_on_launch,
map_public_ip_on_launch,
outpost_arn,
owner_id,
private_dns_name_options_on_launch,
state,
subnet_arn,
subnet_id,
tags,
type,
vpc_id
;

UPDATE examples

Associates a CIDR block with your subnet. You can only associate a single IPv6 CIDR block with your subnet.

UPDATE aws.ec2.subnets
SET
-- No updatable properties
WHERE
SubnetId = '{{ SubnetId }}' --required
AND region = '{{ region }}' --required
AND Ipv6IpamPoolId = '{{ Ipv6IpamPoolId}}'
AND Ipv6NetmaskLength = '{{ Ipv6NetmaskLength}}'
AND Ipv6CidrBlock = '{{ Ipv6CidrBlock}}'
RETURNING
ipv_6_cidr_block_association,
subnet_id;

DELETE examples

Deletes the specified subnet. You must terminate all running instances in the subnet before you can delete the subnet.

DELETE FROM aws.ec2.subnets
WHERE SubnetId = '{{ SubnetId }}' --required
AND region = '{{ region }}' --required
AND DryRun = '{{ DryRun }}'
;

Lifecycle Methods

Modifies a subnet attribute. You can only modify one attribute at a time. Use this action to modify subnets on Amazon Web Services Outposts. To modify a subnet on an Outpost rack, set both MapCustomerOwnedIpOnLaunch and CustomerOwnedIpv4Pool. These two parameters act as a single attribute. To modify a subnet on an Outpost server, set either EnableLniAtDeviceIndex or DisableLniAtDeviceIndex. For more information about Amazon Web Services Outposts, see the following: Outpost servers Outpost racks

EXEC aws.ec2.subnets.modify_subnet_attribute
@SubnetId='{{ SubnetId }}' --required,
@region='{{ region }}' --required,
@AssignIpv6AddressOnCreation='{{ AssignIpv6AddressOnCreation }}',
@MapPublicIpOnLaunch='{{ MapPublicIpOnLaunch }}',
@MapCustomerOwnedIpOnLaunch='{{ MapCustomerOwnedIpOnLaunch }}',
@CustomerOwnedIpv4Pool='{{ CustomerOwnedIpv4Pool }}',
@EnableDns64='{{ EnableDns64 }}',
@PrivateDnsHostnameTypeOnLaunch='{{ PrivateDnsHostnameTypeOnLaunch }}',
@EnableResourceNameDnsARecordOnLaunch='{{ EnableResourceNameDnsARecordOnLaunch }}',
@EnableResourceNameDnsAAAARecordOnLaunch='{{ EnableResourceNameDnsAAAARecordOnLaunch }}',
@EnableLniAtDeviceIndex='{{ EnableLniAtDeviceIndex }}',
@DisableLniAtDeviceIndex='{{ DisableLniAtDeviceIndex }}'
;