Support Documents
No data found.

How to Create Virtual Private Cloud (VPC) with AWS CloudFormation

Lab Details

  1. This lab walks you through how to create a VPC using an AWS CloudFormation Stack. In this lab, we will launch an AWS CloudFormation template to create a two subnets initially. Later we update to four-subnet Amazon VPC that spans two Availability Zones.

  2. Duration: 55 minutes

  3. AWS Region: US East (N. Virginia) us-east-1


What is VPC?

  1. A VPC is similar to a computer network that we can create in an on-premises data center. In the same way, as we create dedicated and private networks within an organization, where computers in a network share network devices such as routers, switches, and so on, we can create a VPC when we create a new account in AWS.

  2. VPC makes it possible to shape similar network infrastructure as we can shape it in our own data center. The difference is, it is a virtual environment within a public cloud wherein the virtual network is logically isolated from other similar networks within the public cloud.

  3. Subnet: Subnet is short for the subnetwork. As we saw at the beginning of this chapter, a network is subdivided into multiple logical parts for controlling access to individual logical subparts of the network.

AWS CloudFormation

  1. CloudFormation is a service provided by AWS for designing our own infrastructure using code i.e infrastructure as code.

  2. Currently, CloudFormation supports two languages JSON and YAML. You can write your code with one of the languages.

  3. CloudFormation comes with great features being able to update your infrastructure whenever you want and also have the ability to delete the stack in case you don’t need it.

  4. A fascinating feature of cloud formation is that it saves more time in building infrastructure and helps in focusing on development.

  5. It is also possible to replicate our infrastructure in a short amount of time.

  6. It eliminates human error and works according to the code you have written. It consists of two main components, Stack and Templates.

CloudFormation Template

  1. It consists of various sections like 

  • AWS Template Format Version

  • Description

  • Metadata

  • Parameters

  • Mappings

  • Conditions

  • Resources (Required Field)

  • Outputs

  1. It is not mandatory that the template requires all the above-mentioned sections. By using only the Resources section, we will be able to create a template.    

  2. The resources section plays an important role in the template creation.

  3. For example, to create an EC2 instance, a template shall consist of various parameters such as key name, image id, instance type.

  4. It is also possible to create two resources in the same template and refer to one from another i.e. attaching an elastic IP with an EC2 instance.

CloudFormation Stack

  1. A stack consists of a collection of resources. 

  2. In other words, the stack consists of one or more templates.

  3. The advantage of the stack is that it is easy to create, delete or update the collection of resources.

  4. The advanced stacks have a nested stack which holds a collection of stacks.

Architecture Diagram

Task Details

  1. Log into the AWS Management Console.

  2. Create Subnets using the VPC_Template cloud formation stack

  3. Create Subnets using the VPC_II_Template cloud formation stack

  4. Deep dive into the  VPC_Template and VPC_II_Template

  5. Validation of the lab.