AWS Tools for Windows PowerShell
Command Reference

AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

Synopsis

Calls the Amazon Elastic Compute Cloud (EC2) CreateSubnet API operation.

Syntax

New-EC2Subnet
-VpcId <String>
-CidrBlock <String>
-AvailabilityZone <String>
-AvailabilityZoneId <String>
-Ipv4IpamPoolId <String>
-Ipv4NetmaskLength <Int32>
-Ipv6CidrBlock <String>
-Ipv6IpamPoolId <String>
-Ipv6Native <Boolean>
-Ipv6NetmaskLength <Int32>
-OutpostArn <String>
-TagSpecification <TagSpecification[]>
-Select <String>
-PassThru <SwitchParameter>
-Force <SwitchParameter>
-ClientConfig <AmazonEC2Config>

Description

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.

Parameters

-AvailabilityZone <String>
The Availability Zone or Local Zone for the subnet.Default: Amazon Web Services 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 Local Zones locations.To create a subnet in an Outpost, set this value to the Availability Zone for the Outpost and specify the Outpost ARN.
Required?False
Position?3
Accept pipeline input?True (ByPropertyName)
-AvailabilityZoneId <String>
The AZ ID or the Local Zone ID of the subnet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-CidrBlock <String>
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.This parameter is not supported for an IPv6 only subnet.
Required?False
Position?2
Accept pipeline input?True (ByPropertyName)
-ClientConfig <AmazonEC2Config>
Amazon.PowerShell.Cmdlets.EC2.AmazonEC2ClientCmdlet.ClientConfig
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
This parameter overrides confirmation prompts to force the cmdlet to continue its operation. This parameter should always be used with caution.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Ipv4IpamPoolId <String>
An IPv4 IPAM pool ID for the subnet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Ipv4NetmaskLength <Int32>
An IPv4 netmask length for the subnet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Ipv6CidrBlock <String>
The IPv6 network range for the subnet, in CIDR notation. This parameter is required for an IPv6 only subnet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Ipv6IpamPoolId <String>
An IPv6 IPAM pool ID for the subnet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Ipv6Native <Boolean>
Indicates whether to create an IPv6 only subnet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Ipv6NetmaskLength <Int32>
An IPv6 netmask length for the subnet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-OutpostArn <String>
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.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-PassThru <SwitchParameter>
Changes the cmdlet behavior to return the value passed to the VpcId parameter. The -PassThru parameter is deprecated, use -Select '^VpcId' instead. This parameter will be removed in a future version.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-Select <String>
Use the -Select parameter to control the cmdlet output. The default value is 'Subnet'. Specifying -Select '*' will result in the cmdlet returning the whole service response (Amazon.EC2.Model.CreateSubnetResponse). Specifying the name of a property of type Amazon.EC2.Model.CreateSubnetResponse will result in that property being returned. Specifying -Select '^ParameterName' will result in the cmdlet returning the selected cmdlet parameter value.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-TagSpecification <TagSpecification[]>
The tags to assign to the subnet.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesTagSpecifications
-VpcId <String>
The ID of the VPC.
Required?True
Position?1
Accept pipeline input?True (ByValue, ByPropertyName)

Common Credential and Region Parameters

-AccessKey <String>
The AWS access key for the user account. This can be a temporary access key if the corresponding session token is supplied to the -SessionToken parameter.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesAK
-Credential <AWSCredentials>
An AWSCredentials object instance containing access and secret key information, and optionally a token for session-based credentials.
Required?False
Position?Named
Accept pipeline input?True (ByValue, ByPropertyName)
-EndpointUrl <String>
The endpoint to make the call against.Note: This parameter is primarily for internal AWS use and is not required/should not be specified for normal usage. The cmdlets normally determine which endpoint to call based on the region specified to the -Region parameter or set as default in the shell (via Set-DefaultAWSRegion). Only specify this parameter if you must direct the call to a specific custom endpoint.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
-NetworkCredential <PSCredential>
Used with SAML-based authentication when ProfileName references a SAML role profile. Contains the network credentials to be supplied during authentication with the configured identity provider's endpoint. This parameter is not required if the user's default network identity can or should be used during authentication.
Required?False
Position?Named
Accept pipeline input?True (ByValue, ByPropertyName)
-ProfileLocation <String>
Used to specify the name and location of the ini-format credential file (shared with the AWS CLI and other AWS SDKs)If this optional parameter is omitted this cmdlet will search the encrypted credential file used by the AWS SDK for .NET and AWS Toolkit for Visual Studio first. If the profile is not found then the cmdlet will search in the ini-format credential file at the default location: (user's home directory)\.aws\credentials.If this parameter is specified then this cmdlet will only search the ini-format credential file at the location given.As the current folder can vary in a shell or during script execution it is advised that you use specify a fully qualified path instead of a relative path.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesAWSProfilesLocation, ProfilesLocation
-ProfileName <String>
The user-defined name of an AWS credentials or SAML-based role profile containing credential information. The profile is expected to be found in the secure credential file shared with the AWS SDK for .NET and AWS Toolkit for Visual Studio. You can also specify the name of a profile stored in the .ini-format credential file used with the AWS CLI and other AWS SDKs.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesStoredCredentials, AWSProfileName
-Region <Object>
The system name of an AWS region or an AWSRegion instance. This governs the endpoint that will be used when calling service operations. Note that the AWS resources referenced in a call are usually region-specific.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesRegionToCall
-SecretKey <String>
The AWS secret key for the user account. This can be a temporary secret key if the corresponding session token is supplied to the -SessionToken parameter.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesSK, SecretAccessKey
-SessionToken <String>
The session token if the access and secret keys are temporary session-based credentials.
Required?False
Position?Named
Accept pipeline input?True (ByPropertyName)
AliasesST

Outputs

This cmdlet returns an Amazon.EC2.Model.Subnet object. The service call response (type Amazon.EC2.Model.CreateSubnetResponse) can also be referenced from properties attached to the cmdlet entry in the $AWSHistory stack.

Examples

Example 1

New-EC2Subnet -VpcId vpc-12345678 -CidrBlock 10.0.0.0/24

AvailabilityZone : us-west-2c
AvailableIpAddressCount : 251
CidrBlock : 10.0.0.0/24
DefaultForAz : False
MapPublicIpOnLaunch : False
State : pending
SubnetId : subnet-1a2b3c4d
Tag : {}
VpcId : vpc-12345678
This example creates a subnet with the specified CIDR.

Supported Version

AWS Tools for PowerShell: 2.x.y.z