CreateSubnet - Amazon Elastic Compute Cloud

CreateSubnet

Creates a subnet in a specified VPC.

You must specify an IPv4 CIDR block for the subnet. After you create a subnet, you can't change its CIDR block. The allowed block size is between a /16 netmask (65,536 IP addresses) and /28 netmask (16 IP addresses). The CIDR block must not overlap with the CIDR block of an existing subnet in the VPC.

If you've associated an IPv6 CIDR block with your VPC, you can create a subnet with an IPv6 CIDR block that uses a /64 prefix length.

Important

AWS reserves both the first four and the last IPv4 address in each subnet's CIDR block. They're not available for use.

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 about subnets, see Your VPC and Subnets in the Amazon Virtual Private Cloud User Guide.

Request Parameters

The following parameters are for this specific action. For more information about required and optional parameters that are common to all actions, see Common Query Parameters.

AvailabilityZone

The Availability Zone or Local Zone for the subnet.

Default: AWS selects one for you. If you create more than one subnet in your VPC, we do not necessarily select a different zone for each subnet.

To create a subnet in a Local Zone, set this value to the Local Zone ID, for example us-west-2-lax-1a. For information about the Regions that support Local Zones, see Available Regions in the Amazon Elastic Compute Cloud User Guide.

To create a subnet in an Outpost, set this value to the Availability Zone for the Outpost and specify the Outpost ARN.

Type: String

Required: No

AvailabilityZoneId

The AZ ID or the Local Zone ID of the subnet.

Type: String

Required: No

CidrBlock

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

Type: String

Required: Yes

DryRun

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

Type: Boolean

Required: No

Ipv6CidrBlock

The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a /64 prefix length.

Type: String

Required: No

OutpostArn

The Amazon Resource Name (ARN) of the Outpost. If you specify an Outpost ARN, you must also specify the Availability Zone of the Outpost subnet.

Type: String

Required: No

TagSpecification.N

The tags to assign to the subnet.

Type: Array of TagSpecification objects

Required: No

VpcId

The ID of the VPC.

Type: String

Required: Yes

Response Elements

The following elements are returned by the service.

requestId

The ID of the request.

Type: String

subnet

Information about the subnet.

Type: Subnet object

Errors

For information about the errors that are common to all actions, see Common Client Errors.

Examples

Example 1

This example creates a subnet with CIDR block 10.0.1.0/24 in the VPC with the ID vpc-1a2b3c4d.

Sample Request

https://ec2.amazonaws.com/?Action=CreateSubnet &VpcId=vpc-1a2b3c4d &CidrBlock=10.0.1.0/24 &AUTHPARAMS

Sample Response

<CreateSubnetResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>e6cb93f0-eb09-40ee-b9aa-16db90a0524f</requestId> <subnet> <subnetId>subnet-0397b6c47c42e4dc0</subnetId> <subnetArn>arn:aws:ec2:us-east-2:111122223333:subnet/subnet-0397b6c47cEXAMPLE</subnetArn> <state>pending</state> <ownerId>111122223333</ownerId> <vpcId>vpc-06b7830650EXAMPLE</vpcId> <cidrBlock>10.0.0.0/24</cidrBlock> <ipv6CidrBlockAssociationSet/> <availableIpAddressCount>251</availableIpAddressCount> <availabilityZone>us-east-2a</availabilityZone> <availabilityZoneId>use2-az1</availabilityZoneId> <defaultForAz>false</defaultForAz> <mapPublicIpOnLaunch>false</mapPublicIpOnLaunch> <assignIpv6AddressOnCreation>false</assignIpv6AddressOnCreation> </subnet> </CreateSubnetResponse>

Example 2

This example creates a subnet with an IPv6 CIDR block in the VPC vpc-1a2b3c4d.

Sample Request

https://ec2.amazonaws.com/?Action=CreateSubnet &VpcId=vpc-07e8ffd50fEXAMPLE &CidrBlock=10.0.1.0/24 &Ipv6CidrBlock=2600:1f16:115:200::/64 &AUTHPARAMS

Sample Response

<CreateSubnetResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId> <subnet> <subnetId>subnet-02bf4c428bEXAMPLE</subnetId> <subnetArn>arn:aws:ec2:us-east-2:111122223333:subnet/subnet-02bf4c428bEXAMPLE</subnetArn> <state>available</state> <ownerId>111122223333</ownerId> <vpcId>vpc-07e8ffd50fEXAMPLE</vpcId> <cidrBlock>10.0.0.0/24</cidrBlock> <ipv6CidrBlockAssociationSet> <item> <ipv6CidrBlock>2600:1f16:115:200::/64</ipv6CidrBlock> <associationId>subnet-cidr-assoc-002afb9f3cEXAMPLE</associationId> <ipv6CidrBlockState> <state>associated</state> </ipv6CidrBlockState> </item> </ipv6CidrBlockAssociationSet> <availableIpAddressCount>251</availableIpAddressCount> <availabilityZone>us-east-2b</availabilityZone> <availabilityZoneId>use2-az2</availabilityZoneId> <defaultForAz>false</defaultForAz> <mapPublicIpOnLaunch>false</mapPublicIpOnLaunch> <assignIpv6AddressOnCreation>false</assignIpv6AddressOnCreation </subnet> </CreateSubnetResponse>

Example 3

This example creates a subnet with an IPv6 CIDR block in the specified Local Zone.

Sample Request

https://ec2.amazonaws.com/?Action=CreateSubnet &VpcId=vpc-07e8ffd50fEXAMPLE &CidrBlock=10.0.1.0/24 &Ipv6CidrBlock=2600:1f16:115:200::/64 &AvailabilityZone=us-west-2-lax-1a &AUTHPARAMS

Sample Response

<CreateSubnetResponse xmlns="http://ec2.amazonaws.com/doc/2016-11-15/"> <requestId>7a62c49f-347e-4fc4-9331-6e8eEXAMPLE</requestId> <subnet> <subnetId>subnet-093cb4a1ecEXAMPLE</subnetId> <subnetArn>arn:aws:ec2:us-west-2:111122223333:subnet/subnet-093cb4a1ecEXAMPLE</subnetArn><subnetArn> <state>available</state> <ownerId>111122223333</ownerId> <vpcId>vpc-07d80fe1a43298172</vpcId> <cidrBlock>10.0.0.0/24</cidrBlock> <ipv6CidrBlockAssociationSet> <item> <ipv6CidrBlock>2600:1f16:115:200::/64</ipv6CidrBlock> <associationId>subnet-cidr-assoc-002afb9f3cEXAMPLE</associationId> <ipv6CidrBlockState> <state>associated</state> </ipv6CidrBlockState> </item> </ipv6CidrBlockAssociationSet> <availableIpAddressCount>251</availableIpAddressCount> <availabilityZone>us-west-2-lax-1a</availabilityZone> <availabilityZoneId>usw2-lax1-az1</availabilityZoneId> <defaultForAz>false</defaultForAz> <mapPublicIpOnLaunch>false</mapPublicIpOnLaunch> <assignIpv6AddressOnCreation>false</assignIpv6AddressOnCreation </subnet> </CreateSubnetResponse>

See Also

For more information about using this API in one of the language-specific AWS SDKs, see the following: