CloudFormation
How to create an AWS VPC with DNS enabled using CloudFormation
The following instructions detail how to create an AWS VPC with DNS enabled using a CloudFormation template.
Before you begin
You must have:
- An AWS account
- Access to a text editor such as Sublime Text or Notepad++
Create a CloudFormation template
Resources to be created by AWS must first be defined in a CloudFormation template, which is a JSON or YAML formatted text file.
Choose your preferred format from the two, and paste one of the code snippets below into a new file in your text editor:
JSON
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation VPC Template",
"Resources": {
"MyCompanyVPC": {
"Type": "AWS::EC2::VPC",
"Properties": {
"CidrBlock": "10.0.0.0/16",
"EnableDnsSupport": true,
"EnableDnsHostnames": true,
"Tags": [{"Key": "Name", "Value": "PrimaryVPC" }]
}
}
}
}
YAML
AWSTemplateFormatVersion: '2010-09-09'
Description: 'AWS CloudFormation VPC Template'
Resources:
MyCompanyVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.0.0.0/16
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: PrimaryVPC
Whichever format is chosen, the code used in both examples will create a VPC with the following settings:
| Setting | Value |
| Logical ID | MyCompanyVPC |
| CIDR Block | 10.0.0.0/16 |
| Name | PrimaryVPC |
If required, modify these values in your text editor to suit your environment.
Note: The Logical ID and CIDR block cannot be changed once the VPC has been created.
Save the file once your template is configured correctly.
Create a VPC from the CloudFormation template
CloudFormation templates are converted to CloudFormation stacks upon upload to AWS. CloudFormation stacks then provision and configure the resources defined in the template file.
Follow these steps to create the VPC from your CloudFormation template:
- Sign in to your AWS account using the web console via aws.amazon.com
- Ensure you are in the correct AWS Region using the navigation bar. Your VPC will be created in this Region.
- Open the CloudFormation service page.
- Select Create stack.
- Select Upload a template file from the Specify template menu.
- Select Choose file and upload your template file.
- Click Next, enter a logical Stack name and click Next again
- Accept the default stack options.
- Review the stack details and select Submit.
CloudFormation will now direct you to the Events tab, a log of the steps taken by AWS to create the defined resources which includes a timestamp and status:
- A status of
CREATE_IN_PROGRESSwill be displayed during the creation of the VPC. - A status of
CREATE_COMPLETEwill be displayed to confirm the successful creation of the VPC.
The Events page automatically refreshes every minute. Click the Resources tab once the stack reaches a CREATE_COMPLETEstatus.
The Physical ID displayed here is a unique identifier assigned to the VPC by AWS. This takes the form of vpc- followed by a unique 17 character string, for example, vpc-0bf8c011c81218c2d.
Click the Physical ID to access the newly created VPC.
The Details tab will allow you to confirm that the VPC Name, IPv4 CIDR and DNS configuration match the settings defined in your original CloudFormation template.