AWS::EC2::Subnet
Creates a subnet in an existing VPC.
Syntax
To declare this entity in your AWS CloudFormation template, use the following syntax:
JSON
{ "Type" : "AWS::EC2::Subnet", "Properties" : { "AssignIpv6AddressOnCreation" :Boolean, "AvailabilityZone" :String, "CidrBlock" :String, "Ipv6CidrBlock" :String, "MapPublicIpOnLaunch" :Boolean, "Tags" : [Resource Tag, ...], "VpcId" :String} }
YAML
Type: AWS::EC2::Subnet Properties: AssignIpv6AddressOnCreation:BooleanAvailabilityZone:StringCidrBlock:StringIpv6CidrBlock:StringMapPublicIpOnLaunch:BooleanTags: -Resource TagVpcId:String
Properties
AssignIpv6AddressOnCreation-
Indicates whether a network interface created in this subnet receives an IPv6 address. The default value is
false.Required: Conditional. If you specify a
trueorfalsevalue forAssignIpv6AddressOnCreation,Ipv6CidrBlockmust also be specified.Type: Boolean
Update requires: No interruption
Note
If
AssignIpv6AddressOnCreationis specified,MapPublicIpOnLaunchcannot be specified. AvailabilityZone-
The availability zone in which you want the subnet. Default: AWS selects a zone for you (recommended).
Required: No
Type: String
Update requires: Replacement
Note
If you update this property, you must also update the
CidrBlockproperty. CidrBlock-
The CIDR block that you want the subnet to cover (for example,
"10.0.0.0/24").Required: Yes
Type: String
Update requires: Replacement
Note
If you update this property, you must also update the
AvailabilityZoneproperty. Ipv6CidrBlock-
The IPv6 network range for the subnet, in CIDR notation. The subnet size must use a
/64prefix length.Required: Conditional. If you specify a
trueorfalsevalue forAssignIpv6AddressOnCreation,Ipv6CidrBlockmust be specified.Type: String
Update requires: No interruption
MapPublicIpOnLaunch-
Indicates whether instances that are launched in this subnet receive a public IP address. By default, the value is
false.Required: No
Type: Boolean
Update requires: No interruption
Note
If
MapPublicIpOnLaunchis specified.AssignIpv6AddressOnCreationcannot be specified. Tags-
An arbitrary set of tags (key–value pairs) for this subnet.
Required: No
Type: Resource Tag
Update requires: No interruption
VpcId-
A Ref structure that contains the ID of the VPC on which you want to create the subnet. The VPC ID is provided as the value of the "Ref" property, as:
{ "Ref": "VPCID" }.Required: Yes
Type: Ref ID
Update requires: Replacement
Note
If you update this property, you must also update the
CidrBlockproperty.
Return Values
You can pass the logical ID of the resource to an intrinsic function to get a value back from the resource. The value that is returned depends on the function that you used.
Ref
When the logical ID of this resource is provided to the Ref
intrinsic function, Ref returns the resource ID, such as
subnet-e19f0178.
For more information about using the Ref function, see Ref.
Fn::GetAtt
Fn::GetAtt returns a value for a specified attribute of this type.
The following are the available attributes and sample return values.
AvailabilityZone-
Returns the availability zone (for example, "
us-east-1a") of this subnet.Example:
{ "Fn::GetAtt" : [ "mySubnet", "AvailabilityZone" ] } Ipv6CidrBlocks-
A list of IPv6 CIDR blocks that are associated with the subnet, such as
[ 2001:db8:1234:1a00::/64 ]. NetworkAclAssociationId-
The ID of the network ACL that is associated with the subnet's VPC, such as
acl-5fb85d36. VpcId-
The ID of the subnet's VPC, such as
vpc-11ad4878.
For more information about using Fn::GetAtt, see Fn::GetAtt.
Example
The following example snippet uses the VPC ID from a VPC named myVPC that was declared elsewhere in the same template.
JSON
{ "AWSTemplateFormatVersion" : "2010-09-09", "Resources" : { "mySubnet" : { "Type" : "AWS::EC2::Subnet", "Properties" : { "VpcId" : { "Ref" : "myVPC" }, "CidrBlock" : "10.0.0.0/24", "AvailabilityZone" : "us-east-1a", "Tags" : [ { "Key" : "foo", "Value" : "bar" } ] } } } }
YAML
AWSTemplateFormatVersion: '2010-09-09' Resources: mySubnet: Type: AWS::EC2::Subnet Properties: VpcId: Ref: myVPC CidrBlock: 10.0.0.0/24 AvailabilityZone: "us-east-1a" Tags: - Key: foo Value: bar
More Info
-
CreateSubnet in the Amazon EC2 API Reference
-
Using Tags in the Amazon Elastic Compute Cloud User Guide
