Menu
AWS CloudFormation
User Guide (API Version 2010-05-15)

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

Copy
{ "Type" : "AWS::EC2::Subnet", "Properties" : { "AssignIpv6AddressOnCreation" : Boolean, "AvailabilityZone" : String, "CidrBlock" : String, "Ipv6CidrBlock" : String, "MapPublicIpOnLaunch" : Boolean, "Tags" : [ Resource Tag, ... ], "VpcId" : String } }

YAML

Copy
Type: "AWS::EC2::Subnet" Properties: AssignIpv6AddressOnCreation: Boolean AvailabilityZone: String CidrBlock: String Ipv6CidrBlock: String MapPublicIpOnLaunch: Boolean Tags: - Resource Tag VpcId: String

Properties

AssignIpv6AddressOnCreation

Indicates whether a network interface created in this subnet receives an IPv6 address.

Required: Conditional. If AssignIpv6AddressOnCreation is true, Ipv6CidrBlock must be specified.

Type: Boolean

Update requires: No interruption

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 CidrBlock property.

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 AvailabilityZone property.

Ipv6CidrBlock

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

Required: No

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

Tags

An arbitrary set of tags (key–value pairs) for this subnet.

Required: No

Type: AWS CloudFormation Resource Tags

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 CidrBlock property.

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:

Copy
{ "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

Copy
{ "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

Copy
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