Amazon VPC Explained: Build Secure, Scalable, and Private Networks on AWS

Amazon VPC Explained: Build Secure, Scalable, and Private Networks on AWS

Learn how Amazon VPC works and how to build your own isolated AWS network. Explore subnets, route tables, gateways, security groups, network ACLs, and practical AWS CLI commands to design secure cloud infrastructure.

Aspiring Cloud & DevOps Engineer | AWS | Linux | Git | Docker

Amazon VPC Explained: Build Secure, Scalable, and Private Networks on AWS

Introduction

When you deploy applications on AWS, one of the first things you need to understand is networking.
Where will your application run? How will it communicate with other services? How can you control who accesses your resources?
This is where Amazon VPC (Virtual Private Cloud) comes into the picture.
Amazon VPC allows you to create your own logically isolated network inside AWS. You can control IP address ranges, create public and private subnets, configure routing, and manage network security.
Whether you are deploying an EC2 instance, hosting a web application, building a Kubernetes cluster with Amazon EKS, or designing a production environment, understanding VPC is an essential AWS skill.
Let's understand how it works and build a basic network using AWS CLI.

1. What is Amazon VPC?

Amazon Virtual Private Cloud (Amazon VPC) is a networking service that allows you to launch AWS resources in a logically isolated virtual network.
Think of a VPC as your own private network in the AWS cloud.
You decide:
  • Which IP address range your network uses.
  • How many subnets you need.
  • Which resources are publicly accessible.
  • How traffic moves between different networks.
  • Which network connections are allowed or blocked.
Real-world example:
Imagine you are building an e-commerce application.
You might have:
  • Public subnet: Hosts the application load balancer.
  • Private subnet: Hosts application servers.
  • Database subnet: Hosts an Amazon RDS database.
Your database does not need direct internet access. Your application servers can communicate with it through private networking.
This separation improves security and makes your architecture easier to manage.

2. Important Components of Amazon VPC

Let's understand the major components.

2.1 VPC

A VPC is the foundation of your AWS network.
Example:
  • VPC CIDR: 10.0.0.0/16
  • Available IP addresses: 65,536 (including reserved address considerations).
You can create a VPC through the AWS Management Console, AWS CLI, SDKs, or infrastructure-as-code tools such as Terraform.

2.2 Subnets

A subnet is a smaller network created inside your VPC.
You can divide your VPC into multiple subnets based on application requirements.
Public Subnet
A public subnet has a route to an Internet Gateway.
Common use cases:
  • Application Load Balancers
  • Public-facing web servers
  • Bastion hosts, when required
Private Subnet
A private subnet does not have a direct route to an Internet Gateway.
Common use cases:
  • Application servers
  • Backend services
  • Databases
  • Internal workloads
You can create subnets in different Availability Zones to improve availability.

2.3 Internet Gateway (IGW)

An Internet Gateway allows communication between resources in your VPC and the public internet when routing and security configurations permit it.
For example, if you want an EC2 instance to serve a public website, you typically need:
  • A subnet route to an Internet Gateway.
  • A public IPv4 address or another suitable public connectivity mechanism.
  • Appropriate security group rules.
Remember: attaching an Internet Gateway alone does not automatically make every EC2 instance publicly accessible.

2.4 Route Tables

A route table determines where network traffic is directed.
Example:
Destination
Target
Purpose
10.0.0.0/16
Local
Internal VPC traffic
0.0.0.0/0
Internet Gateway
Internet-bound IPv4 traffic
10.0.2.0/24
Local routing
VPC internal communication
Every subnet is associated with a route table, either explicitly or through the main route table.

2.5 NAT Gateway

A NAT Gateway allows resources in a private subnet to initiate connections to the internet without allowing unsolicited internet connections to reach those resources.
Example:
An EC2 instance in a private subnet needs to download software updates.
Instead of assigning it a public IP address, you can configure a route through a NAT Gateway.

2.6 Security Groups

Security Groups act as virtual firewalls for AWS resources.
They control inbound and outbound traffic.
Important points:
  • Security groups are stateful.
  • They support allow rules.
  • They are associated with network interfaces and resources.
  • Return traffic for allowed connections is automatically permitted.
Example:
Allow HTTP traffic on port 80 and HTTPS traffic on port 443 for a public web server.

2.7 Network ACLs (NACLs)

Network ACLs provide an additional security layer at the subnet level.
Important points:
  • NACLs are stateless.
  • They support allow and deny rules.
  • They evaluate rules in numerical order.
  • Both inbound and outbound rules must be considered.

3. How Amazon VPC Architecture Works

Let's consider a simple three-tier application architecture.
Architecture:
Internet Users → Internet Gateway → Public Subnet → Application Layer → Private Subnet → Database Layer
A typical production design may include:
  1. A VPC with CIDR 10.0.0.0/16.
  1. Public subnets in multiple Availability Zones.
  1. Private application subnets.
  1. Isolated database subnets.
  1. Internet Gateway for public connectivity.
  1. NAT Gateway for private outbound internet access.
  1. Security Groups and NACLs for network protection.
The goal is to expose only the components that need public access.

4. Hands-on: Create an Amazon VPC Using AWS CLI

Now let's create a basic VPC using AWS CLI.

Prerequisites

Before starting, make sure you have:
  • An AWS account.
  • AWS CLI installed.
  • Configured AWS credentials.
  • Appropriate IAM permissions.
  • A selected AWS Region.
Verify your AWS CLI configuration:
aws sts get-caller-identity
Check your AWS Region:
aws configure get region
For this example, we will use:
Component
CIDR
VPC
10.0.0.0/16
Public Subnet
10.0.1.0/24
Private Subnet
10.0.2.0/24
Use an appropriate Availability Zone in your selected Region.

Step 1: Create a VPC

VPC_ID=$(aws ec2 create-vpc \
--cidr-block 10.0.0.0/16 \
--query 'Vpc.VpcId' \
--output text)

echo "$VPC_ID"
Enable DNS support:
aws ec2 modify-vpc-attribute \
--vpc-id "$VPC_ID" \
--enable-dns-support Value=true
Enable DNS hostnames:
aws ec2 modify-vpc-attribute \
--vpc-id "$VPC_ID" \
--enable-dns-hostnames Value=true

Step 2: Create a Public Subnet

AZ="YOUR_AVAILABILITY_ZONE"

PUBLIC_SUBNET_ID=$(aws ec2 create-subnet \
--vpc-id "$VPC_ID" \
--cidr-block 10.0.1.0/24 \
--availability-zone "$AZ" \
--query 'Subnet.SubnetId' \
--output text)

echo "$PUBLIC_SUBNET_ID"
Enable automatic public IPv4 assignment:
aws ec2 modify-subnet-attribute \
--subnet-id "$PUBLIC_SUBNET_ID" \
--map-public-ip-on-launch

Step 3: Create a Private Subnet

PRIVATE_SUBNET_ID=$(aws ec2 create-subnet \
--vpc-id "$VPC_ID" \
--cidr-block 10.0.2.0/24 \
--availability-zone "$AZ" \
--query 'Subnet.SubnetId' \
--output text)

echo "$PRIVATE_SUBNET_ID"

Step 4: Create and Attach an Internet Gateway

IGW_ID=$(aws ec2 create-internet-gateway \
--query 'InternetGateway.InternetGatewayId' \
--output text)

aws ec2 attach-internet-gateway \
--vpc-id "$VPC_ID" \
--internet-gateway-id "$IGW_ID"

Step 5: Create a Public Route Table

PUBLIC_RT_ID=$(aws ec2 create-route-table \
--vpc-id "$VPC_ID" \
--query 'RouteTable.RouteTableId' \
--output text)
Add a default internet route:
aws ec2 create-route \
--route-table-id "$PUBLIC_RT_ID" \
--destination-cidr-block 0.0.0.0/0 \
--gateway-id "$IGW_ID"
Associate the route table with the public subnet:
aws ec2 associate-route-table \
--route-table-id "$PUBLIC_RT_ID" \
--subnet-id "$PUBLIC_SUBNET_ID"
Your public subnet now has a route to the internet. Actual connectivity still depends on public addressing and security configuration.

Step 6: Verify Your VPC

List your VPCs:
aws ec2 describe-vpcs
List your subnets:
aws ec2 describe-subnets \
--filters "Name=vpc-id,Values=$VPC_ID"
List your route tables:
aws ec2 describe-route-tables \
--filters "Name=vpc-id,Values=$VPC_ID"
Congratulations! You have created a basic AWS network with public and private subnets.
Note: This is a learning environment, not a complete production deployment. The private subnet has no NAT Gateway or VPC endpoint configured in this example.

5. Public Subnet vs Private Subnet

Feature
Public Subnet
Private Subnet
Internet Gateway route
Yes
No direct route
Public IP
Can be assigned
Usually not assigned
Internet access
Possible
Through NAT or endpoints
Typical resources
Load balancers
App servers and databases
Security
Controlled by security rules
Controlled by security rules

6. Security Groups vs Network ACLs

Both help protect your AWS network, but they work differently.
Feature
Security Group
Network ACL
Level
Resource/network interface
Subnet
Stateful
Yes
No
Rules
Allow only
Allow and deny
Rule evaluation
All applicable rules
Numbered order
Default behavior
Deny inbound, allow outbound by default
Default NACL allows all traffic
A good approach is to use Security Groups as your primary resource-level security control and NACLs as an additional subnet-level security layer where needed.

7. AWS VPC Security Best Practices

Security should be considered from the beginning of your network design.
Here are some important practices:
1. Follow Least Privilege
Allow only the required traffic and ports. Avoid opening unnecessary inbound connections.
2. Keep Databases Private
Never expose database servers directly to the public internet. Use private subnets and restrict database access to authorized application resources.
3. Restrict SSH and RDP
Avoid allowing SSH (port 22) or RDP (port 3389) from 0.0.0.0/0. Use Systems Manager Session Manager or restricted trusted source addresses where appropriate.
4. Use Multiple Availability Zones
Deploy critical workloads across multiple Availability Zones to improve resilience.
5. Enable VPC Flow Logs
VPC Flow Logs help capture information about IP traffic going to and from network interfaces in your VPC. They are useful for monitoring and troubleshooting.
6. Use VPC Endpoints
VPC Endpoints allow private connectivity to supported AWS services without requiring traffic to travel through the public internet.
7. Monitor Network Activity
Use Amazon CloudWatch and other AWS monitoring services to observe network behavior and investigate unexpected traffic.
8. Use Infrastructure as Code
Use Terraform or AWS CloudFormation to create and manage repeatable VPC configurations.

8. Where Is Amazon VPC Used in Real Projects?

Amazon VPC is used in many cloud infrastructure scenarios.
Use Case
How VPC Helps
Web Applications
Separates public and backend resources
Microservices
Provides controlled private communication
Amazon EKS
Supports Kubernetes networking
Database Hosting
Keeps databases in private networks
Hybrid Cloud
Connects AWS with on-premises networks
DevOps Infrastructure
Supports secure CI/CD and deployment environments
For DevOps engineers, VPC knowledge is particularly important when deploying EC2 instances, configuring load balancers, creating Kubernetes clusters, and building production infrastructure using Terraform.

9. Key Takeaways

Let's quickly revise what we learned:
  • Amazon VPC provides an isolated virtual network inside AWS.
  • Subnets divide your VPC into smaller networks.
  • Internet Gateways provide internet connectivity for appropriately configured public resources.
  • NAT Gateways allow private resources to initiate outbound internet connections.
  • Route Tables control network traffic destinations.
  • Security Groups protect resources.
  • Network ACLs provide subnet-level traffic filtering.
  • VPC Endpoints provide private access to supported AWS services.

Conclusion

Amazon VPC is one of the most important building blocks of AWS infrastructure.
Understanding VPC, subnets, routing, gateways, and security controls helps you design cloud environments that are secure, scalable, and reliable.
If you are learning AWS or preparing for a Cloud Engineer or DevOps Engineer role, don't just memorize the concepts. Create your own VPC, launch resources, configure routes, test connectivity, and understand how traffic flows.
Your next step: Try recreating this architecture using Terraform and deploy a simple web application on EC2.
Keep building, keep learning, and keep exploring AWS!


Let's Connect and Learn Together!
Have you built your own VPC architecture? Share your experience, questions, or useful tips in the comments.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article