Understanding Amazon VPC: Build a Secure Network in AWS
Learn how Amazon VPC works, including subnets, route tables, internet gateways, NAT gateways, security groups, and network ACLs, with a practical architecture example.
Understanding Amazon VPC: Build a Secure Network in AWS
When you deploy applications on AWS, networking is one of the first things you need to understand. Amazon Virtual Private Cloud (Amazon VPC) allows you to create a logically isolated network where you can securely run AWS resources such as EC2 instances, databases, and load balancers.
In this article, we'll explore the core components of a VPC and see how they work together to create a secure and scalable cloud network.
What is a VPC?
A Virtual Private Cloud (VPC) is a logically isolated network inside AWS.
Think of a VPC as your own private data-center network in the cloud. You control important networking settings such as:
IP address ranges
Subnets
Routing
Internet connectivity
Network security
Communication between resources
For example, you might create a VPC using the CIDR block:
10.0.0.0/16
This provides a private IP address space that can be divided into multiple subnets.
Why Do We Need a VPC?
A VPC gives you control over how your AWS resources communicate.
For example, a typical web application might contain:
Internet
|
Internet Gateway
|
+------------------+
| VPC |
| 10.0.0.0/16 |
| |
| Public Subnet |
| Web Servers |
| |
| Private Subnet |
| Application |
| |
| Private Subnet |
| Database |
+------------------+The web servers can receive traffic from the internet, while application servers and databases can remain private.
This separation improves security and gives you more control over network traffic.
Important Components of a VPC
Let's look at the most important VPC components.
- CIDR Block A VPC requires an IP address range.
For example:
10.0.0.0/16
The /16 determines how many IP addresses are available within the network.
You can divide the VPC into smaller subnet ranges.
For example:
VPC: 10.0.0.0/16
Public Subnet: 10.0.1.0/24
Private Subnet: 10.0.2.0/24
Database Subnet: 10.0.3.0/24
Planning your CIDR ranges carefully is important, especially when you expect to connect your VPC to other networks later.
- Subnets A subnet is a smaller network inside your VPC.
Subnets are associated with a specific Availability Zone.
There are two common types:
Public Subnet
A public subnet has a route to an Internet Gateway.
Resources such as public-facing load balancers or web servers may be placed here.
Private Subnet
A private subnet does not have a direct route to the internet through an Internet Gateway.
Application servers and databases are commonly placed in private subnets.
A common architecture looks like this:
VPC
|
+-- Public Subnet
| +-- Load Balancer
| +-- Web Server
|
+-- Private Subnet
| +-- Application Server
|
+-- Database Subnet
+-- Database
3. Internet Gateway
An Internet Gateway (IGW) allows resources in a VPC to communicate with the public internet when the appropriate routing and public addressing are configured.
A public subnet typically has a route such as:
0.0.0.0/0 → Internet Gateway
The 0.0.0.0/0 route represents destinations outside the VPC's local network.
An Internet Gateway is horizontally scaled and managed by AWS, so you don't have to operate the underlying infrastructure.
- Route Tables A route table determines where network traffic should go.
For example, a public subnet might have:
Destination Target
10.0.0.0/16 local
0.0.0.0/0 Internet Gateway
The first route allows communication within the VPC.
The second route sends internet-bound traffic to the Internet Gateway.
Private subnets can have different routes depending on the architecture.
- NAT Gateway Applications in private subnets sometimes need to access the internet—for example, to download software updates or call public APIs.
A NAT Gateway can provide outbound internet connectivity for resources in a private subnet without making those resources directly reachable from the internet.
A simplified architecture is:
Private Subnet
|
v
NAT Gateway
|
v
Internet Gateway
|
v
Internet
The NAT Gateway is normally placed in a public subnet.
A private subnet can then route internet-bound traffic through it:
0.0.0.0/0 → NAT Gateway
6. Security Groups
A security group acts as a virtual firewall for supported AWS resources.
Security groups control traffic at the resource level.
For example, a web server security group might allow:
HTTP → TCP 80
HTTPS → TCP 443
SSH → TCP 22
However, SSH access should generally be restricted to trusted sources rather than allowing the entire internet.
Security groups are stateful, meaning that when an allowed connection is established, the return traffic is automatically allowed.
- Network ACLs A Network Access Control List (Network ACL) provides another layer of network traffic control at the subnet level.
Unlike security groups, network ACLs are stateless.
This means inbound and outbound traffic rules need to be considered separately.
A useful way to remember the difference is:
Security Group → Resource level
Network ACL → Subnet level
For many applications, security groups provide the primary day-to-day network access controls, while network ACLs can provide an additional subnet-level layer.
Putting Everything Together
Consider a three-tier application:
Internet
|
v
Internet Gateway
|
+---------------+
| Public Subnet |
| |
| Load Balancer |
+-------+-------+
|
v
+---------------+
| Private |
| App Subnet |
| |
| App Servers |
+-------+-------+
|
v
+---------------+Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article