AWS CloudFormation
User Guide (API Version 2010-05-15)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

AWS::EC2::Subnet

Creates a subnet in an existing VPC.

Syntax

{
   "Type" : "AWS::EC2::Subnet",
   "Properties" : {
      "AvailabilityZone" : String,
      "CidrBlock" : String,
      "Tags" : [ EC2 Tag, ... ],
      "VpcId" : { "Ref" : String }
   }
}     

Properties

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. Modifying this property requires that the CIDR block be changed.

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

Tags

The tags that you want to attach to this resource.

Required: No

Type: A list of EC2 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. Modifying this property requires that the CIDR block be changed.

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

Ref

When the logical ID of this resource is provided to the Ref intrinsic function, it returns the resource name.

For more information about using the Ref function, see Ref.

Fn::GetAtt

Fn::GetAtt returns a value for a specified attribute of this type. This section lists the available attributes and corresponding return values.

AvailabilityZone

Returns the availability zone (for example, "us-east-1a") of this subnet.

Example:

{ "Fn::GetAtt" : [ "mySubnet", "AvailabilityZone" ] } 

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.

{
   "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" } ]
         }
      }
   }
}     

See Also

  • CreateSubnet in the Amazon Elastic Compute Cloud API Reference

  • Using Tags in the Amazon Elastic Compute Cloud User Guide