aws ec2 create-subnet
Creates a subnet in the specified VPC. AWS CLI reference
3 examples 13 options Its page in the AWS CLI reference
Examples
Example 1: To create a subnet with an IPv4 CIDR block only
The following create-subnet example creates a subnet in the specified VPC with the specified IPv4 CIDR block.
aws ec2 create-subnet --vpc-id vpc-081ec835f3EXAMPLE --cidr-block 10.0.0.0/24 --tag-specifications ResourceType=subnet,Tags=[{Key=Name,Value=my-ipv4-only-subnet}]Identify--vpc-idThe ID of the VPC.--cidr-blockThe IPv4 network range for the subnet, in CIDR notation.--tag-specificationsThe tags to assign to the subnet.Its output
{
"Subnet": {
"AvailabilityZone": "us-west-2a",
"AvailabilityZoneId": "usw2-az2",
"AvailableIpAddressCount": 251,
"CidrBlock": "10.0.0.0/24",
"DefaultForAz": false,
"MapPublicIpOnLaunch": false,
"State": "available",
"SubnetId": "subnet-0e99b93155EXAMPLE",
"VpcId": "vpc-081ec835f3EXAMPLE",
"OwnerId": "123456789012",
"AssignIpv6AddressOnCreation": false,
"Ipv6CidrBlockAssociationSet": [],
"Tags": [
{
"Key": "Name",
"Value": "my-ipv4-only-subnet"
}
],
"SubnetArn": "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-0e99b93155EXAMPLE"
}
}Example 2: To create a subnet with both IPv4 and IPv6 CIDR blocks
The following create-subnet example creates a subnet in the specified VPC with the specified IPv4 and IPv6 CIDR blocks.
aws ec2 create-subnet --vpc-id vpc-081ec835f3EXAMPLE --cidr-block 10.0.0.0/24 --ipv6-cidr-block 2600:1f16:cfe:3660::/64 --tag-specifications ResourceType=subnet,Tags=[{Key=Name,Value=my-ipv4-ipv6-subnet}]Identify--vpc-idThe ID of the VPC.--cidr-blockThe IPv4 network range for the subnet, in CIDR notation.--ipv6-cidr-blockThe IPv6 network range for the subnet, in CIDR notation.--tag-specificationsThe tags to assign to the subnet.Its output, shortened
{
"Subnet": {
"AvailabilityZone": "us-west-2a",
"AvailabilityZoneId": "usw2-az2",
"AvailableIpAddressCount": 251,
"CidrBlock": "10.0.0.0/24",
"DefaultForAz": false,
"MapPublicIpOnLaunch": false,
"State": "available",
"SubnetId": "subnet-0736441d38EXAMPLE",
"VpcId": "vpc-081ec835f3EXAMPLE",
"OwnerId": "123456789012",
"AssignIpv6AddressOnCreation": false,
"Ipv6CidrBlockAssociationSet": [
{
"AssociationId": "subnet-cidr-assoc-06c5f904499fcc623",
"Ipv6CidrBlock": "2600:1f13:cfe:3660::/64",
"Ipv6CidrBlockState": {
"State": "associating"
}
}
],
"Tags": [
{
"Key": "Name",
"Value": "my-ipv4-ipv6-subnet"
}
],
"SubnetArn": "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-0736441d38EXAMPLE"
}
… 1 more lineExample 3: To create a subnet with an IPv6 CIDR block only
The following create-subnet example creates a subnet in the specified VPC with the specified IPv6 CIDR block.
aws ec2 create-subnet --vpc-id vpc-081ec835f3EXAMPLE --ipv6-native --ipv6-cidr-block 2600:1f16:115:200::/64 --tag-specifications ResourceType=subnet,Tags=[{Key=Name,Value=my-ipv6-only-subnet}]Identify--vpc-idThe ID of the VPC.--ipv6-nativeIndicates whether to create an IPv6 only subnet.--ipv6-cidr-blockThe IPv6 network range for the subnet, in CIDR notation.--tag-specificationsThe tags to assign to the subnet.Its output
{
"Subnet": {
"AvailabilityZone": "us-west-2a",
"AvailabilityZoneId": "usw2-az2",
"AvailableIpAddressCount": 0,
"DefaultForAz": false,
"MapPublicIpOnLaunch": false,
"State": "available",
"SubnetId": "subnet-03f720e7deEXAMPLE",
"VpcId": "vpc-081ec835f3EXAMPLE",
"OwnerId": "123456789012",
"AssignIpv6AddressOnCreation": true,
"Ipv6CidrBlockAssociationSet": [
{
"AssociationId": "subnet-cidr-assoc-01ef639edde556709",
"Ipv6CidrBlock": "2600:1f13:cfe:3660::/64",
"Ipv6CidrBlockState": {
"State": "associating"
}
}
],
"Tags": [
{
"Key": "Name",
"Value": "my-ipv6-only-subnet"
}
],
"SubnetArn": "arn:aws:ec2:us-west-2:123456789012:subnet/subnet-03f720e7deEXAMPLE"
}
}For more information, see VPCs and subnets in the Amazon VPC User Guide.
Options
--availability-zone-idThe AZ ID or the Local Zone ID of the subnet.--availability-zoneThe Availability Zone or Local Zone for the subnet.--cidr-blockThe IPv4 network range for the subnet, in CIDR notation.--dry-runChecks whether you have the required permissions for the action, without actually making the request, and provides an error response.--ipv4-ipam-pool-idAn IPv4 IPAM pool ID for the subnet.--ipv4-netmask-lengthAn IPv4 netmask length for the subnet.--ipv6-cidr-blockThe IPv6 network range for the subnet, in CIDR notation.--ipv6-ipam-pool-idAn IPv6 IPAM pool ID for the subnet.--ipv6-nativeIndicates whether to create an IPv6 only subnet.--ipv6-netmask-lengthAn IPv6 netmask length for the subnet.--outpost-arnThe Amazon Resource Name (ARN) of the Outpost.--tag-specificationsThe tags to assign to the subnet.--vpc-idThe ID of the VPC.