
Amazon VPC for Beginners: How AWS Networking Works
In this Week 8 article, learn how Amazon VPC works and how AWS networking is structured. Explore subnets, Internet Gateways, NAT Gateways, route tables, Security Groups, and Network ACLs. Follow a practical MERN application architecture to understand how to build secure cloud networks. A beginner-friendly introduction to one of the most important foundations of AWS.
Introduction
When you launch an EC2 instance, where does it actually live? How does it connect to the internet? How can you make a server publicly accessible while keeping your database private?
The answer to these questions starts with Amazon Virtual Private Cloud (Amazon VPC).
A VPC is one of the most important networking services in AWS. It allows you to create an isolated virtual network where you can launch and connect AWS resources such as EC2 instances, databases, and load balancers.
In this article, we'll understand VPC networking from scratch, explore its major components, and design a practical network architecture for a MERN stack application.
1. What is Amazon VPC?
Amazon VPC (Virtual Private Cloud) is a logically isolated virtual network inside AWS where you control how your resources communicate with each other and the outside world.
Think of it like creating your own private network in the cloud.
In a traditional data center, network administrators configure:
- IP address ranges
- Subnets
- Routers
- Firewalls
- Internet connectivity
Amazon VPC provides similar networking capabilities through AWS-managed infrastructure.
For example:
Suppose you're building an e-commerce application. You might want:
- A web server accessible to users over the internet.
- A backend server that handles application logic.
- A database that cannot be accessed directly from the internet.
A VPC helps you organize and secure these resources.
2. Understanding the basic VPC architecture
A VPC is created inside an AWS Region and can span multiple Availability Zones.
However, each subnet belongs to exactly one Availability Zone.
Here is a simplified example:
AWS REGION | +------------------+ | Amazon VPC | | 10.0.0.0/16 | | | | +------------+ | | | Public | | | | Subnet | | | | 10.0.1.0/24| | | | | | | | Load | | | | Balancer | | | +------------+ | | | | +------------+ | | | Private | | | | Subnet | | | | 10.0.2.0/24| | | | | | | | Backend | | | | Server | | | +------------+ | | | +------------------+Let's understand each component.
3. Important components of Amazon VPC
A. CIDR Block and IP Addressing
When creating a VPC, you define an IP address range using CIDR notation.
CIDR stands for Classless Inter-Domain Routing.
For example:
10.0.0.0/16This represents the IP address range allocated to your VPC.
You can divide this range into smaller subnet ranges:
Network | CIDR block |
|---|---|
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 |
This helps organize resources into different network sections.
B. Subnets
A subnet is a smaller network created inside a VPC.
You can place different resources in different subnets depending on their connectivity requirements.
There are two major types:
1. Public Subnet
A public subnet has a route to an Internet Gateway.
It is commonly used for resources that need direct internet connectivity, such as:
- Internet-facing load balancers
- Public web servers
- NAT Gateways
A route to an Internet Gateway alone does not automatically make an instance publicly accessible. The instance also needs appropriate IP addressing and security rules.
2. Private Subnet
A private subnet does not have a direct route to an Internet Gateway.
It is commonly used for:
- Backend application servers
- Databases
- Internal services
- Sensitive application components
Resources in private subnets can communicate with other permitted resources inside the VPC. They can also access the internet through a NAT Gateway when outbound connectivity is required.
C. Internet Gateway (IGW)
An Internet Gateway allows communication between resources in a VPC and the public internet.
Imagine that your EC2 instance hosts a website. Users need a way to reach that server from their browsers.
An Internet Gateway provides the VPC-level connection needed for internet communication.
Basic flow:
User's Browser | Internet |Internet Gateway | Public Subnet | EC2 InstanceTo enable internet connectivity, you generally need to:
- Create an Internet Gateway.
- Attach it to your VPC.
- Add a default route to the Internet Gateway in the subnet's route table.
- Ensure the resource has appropriate public IP addressing.
- Configure security rules to permit the required traffic.
D. Route Tables
A route table determines where network traffic should go.
Think of it as a traffic controller for your VPC.
Each route contains:
- Destination: Where the traffic needs to go.
- Target: Where the traffic should be sent.
Example public subnet route table:
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 other IPv4 traffic toward the internet.
For a private subnet, the default route might point to a NAT Gateway instead.
E. NAT Gateway
NAT stands for Network Address Translation.
A NAT Gateway allows resources in a private subnet to initiate connections to the internet without allowing unsolicited inbound internet connections directly to those resources.
For example, your private backend server may need to:
- Download software updates.
- Install dependencies.
- Connect to external APIs.
But you don't want users on the internet to connect directly to that server.
A NAT Gateway helps achieve this.
Private EC2 Instance | NAT Gateway | Internet Gateway | InternetFor IPv4 internet access, a public NAT Gateway is placed in a public subnet and uses an Elastic IP address.
Important: NAT Gateways have associated costs, so remember to remove unused ones in learning environments.
F. Security Groups
A Security Group works like a virtual firewall for resources such as EC2 instances.
It controls inbound and outbound traffic.
For example, if you host a website on an EC2 instance, you might configure:
Type | Port | Purpose |
|---|---|---|
HTTP | 80 | Website traffic |
HTTPS | 443 | Secure website traffic |
SSH | 22 | Server administration |
You should restrict SSH access to your own trusted IP address rather than allowing access from everywhere.
Security Groups are stateful. This means response traffic for an allowed connection is automatically permitted.
G. Network Access Control Lists (NACLs)
A Network ACL is another security layer that controls traffic at the subnet level.
It supports both allow and deny rules.
For example, you can configure a NACL to allow HTTP traffic and deny traffic from a particular IP range.
Unlike Security Groups, NACLs are stateless. You must account for both inbound and outbound traffic, including response traffic.
4. Security Groups vs Network ACLs
This is an important AWS networking interview topic.
Feature | Security Group | Network ACL |
|---|---|---|
Applied at | Resource level | Subnet level |
Rules | Allow only | Allow and deny |
Stateful | Yes | No |
Rule evaluation | All applicable rules | In rule-number order |
Default behavior | No inbound rules | Default ACL allows traffic |
Easy way to remember:
- Security Group = Firewall for an individual resource.
- Network ACL = Firewall for an entire subnet.
AWS generally recommends Security Groups as the primary mechanism for controlling network access, with NACLs available as an additional layer.
5. How all these components work together
Let's understand a complete request flow.
Imagine someone opens your website.
- The user sends an HTTP or HTTPS request.
- The request reaches your VPC through the Internet Gateway and the public-facing network path.
- The route table directs traffic toward the appropriate destination.
- The Network ACL evaluates traffic entering the subnet.
- The Security Group checks whether the resource allows the connection.
- The load balancer forwards the request to an application server.
- The application server communicates with the database over the private network.
This architecture helps separate public-facing resources from internal application resources.
6. Practical example: VPC architecture for a MERN application
Suppose you're building an e-commerce application using:
- MongoDB
- Express.js
- React.js
- Node.js
You can design the AWS network like this:
INTERNET | Internet Gateway | PUBLIC SUBNET | Application Load Balancer | --------------------- | | PRIVATE SUBNET PRIVATE SUBNET (AZ 1) (AZ 2) | | Node.js Server Node.js Server | | --------------------- | DATABASE SUBNET | MongoDB / DatabaseThe architecture separates the application into different layers.
Frontend:
- React application can be hosted using Amazon S3 and CloudFront.
- Users access the frontend through a public website URL.
Backend:
- Node.js and Express.js servers run on EC2 instances in private subnets.
- An Application Load Balancer receives public requests and forwards them to the backend servers.
Database:
- The database runs in private subnets.
- Only authorized backend resources can connect to it.
Networking:
- Internet Gateway provides public internet connectivity.
- Route tables control traffic paths.
- NAT Gateway provides outbound internet access to private IPv4 resources when required.
- Security Groups restrict communication between application layers.
This is a more secure and scalable approach than exposing every server directly to the internet.
7. How to create your first VPC
You can explore VPC using the AWS Management Console.
Follow these steps:
Step 1: Open the VPC Console
Visit:
Step 2: Create a VPC
- Select Your VPCs.
- Choose Create VPC.
- Enter a name, such as
MyFirstVPC.
- Select an IPv4 CIDR block, such as
10.0.0.0/16.
- Create the VPC.
Step 3: Create Subnets
Create two subnets:
- Public subnet:
10.0.1.0/24
- Private subnet:
10.0.2.0/24
Choose an Availability Zone for each subnet.
Step 4: Create an Internet Gateway
- Open Internet Gateways.
- Create an Internet Gateway.
- Attach it to your VPC.
Step 5: Configure Route Tables
For the public subnet:
Destination Target10.0.0.0/16 local0.0.0.0/0 Internet GatewayAssociate this route table with your public subnet.
For the private subnet, keep the local route. Add a NAT Gateway route only if you need outbound IPv4 internet access.
Step 6: Configure Security Groups
Allow only the traffic your application requires.
For example:
- HTTP: Port 80
- HTTPS: Port 443
- SSH: Port 22, restricted to your IP address
You now understand the basic building blocks of a VPC.
For a beginner lab, you can start with a simple public subnet. Avoid creating a NAT Gateway unless you specifically need it, because it can incur charges.
8. Common mistakes beginners should avoid
- Making everything public: Databases and internal services should generally remain in private subnets.
- Opening SSH to everyone: Avoid allowing port 22 from
0.0.0.0/0.
- Forgetting route tables: An Internet Gateway attachment alone does not provide internet access to a subnet.
- Ignoring Availability Zones: Production architectures should consider deploying resources across multiple Availability Zones.
- Ignoring costs: NAT Gateways and public IPv4 addresses can incur charges.
- Using overlapping CIDR ranges: Plan IP address ranges carefully, especially when connecting multiple VPCs.
9. Why should developers learn Amazon VPC?
Understanding VPC is useful when working with:
- Cloud infrastructure and networking.
- Backend application deployment.
- Microservices architecture.
- Database security.
- DevOps and cloud engineering.
- AWS certifications and technical interviews.
Even if you use managed services, understanding networking helps you troubleshoot connectivity and security problems.
10. Key Takeaways
- Amazon VPC provides an isolated virtual network in AWS.
- Subnets divide a VPC into smaller network sections.
- Public subnets have a direct route to an Internet Gateway.
- Private subnets do not have a direct route to an Internet Gateway.
- Route tables control where network traffic goes.
- NAT Gateways allow private IPv4 resources to initiate outbound internet connections.
- Security Groups protect individual resources.
- Network ACLs control traffic at the subnet level.
Conclusion
Amazon VPC is the foundation of networking in AWS.
Understanding VPC, subnets, route tables, gateways, and security rules makes it much easier to deploy applications securely in the cloud.
If you're learning AWS, don't just memorize these components. Create a VPC, launch an EC2 instance, configure a subnet, and experiment with network connectivity.
Hands-on practice is the best way to understand cloud networking.
In the next article, we'll explore AWS IAM (Identity and Access Management) and understand how AWS controls who can access which resources.
Official AWS Learning Resources
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article