Building Isolated Networks with Amazon VPC
This lesson explains how Amazon Virtual Private Cloud (Amazon VPC) lets you create a logically isolated network in AWS, controlling IP addresses, subnets, routing and security.
Learning outcomes
After completing this lesson, you will be able to:
- Describe the building blocks of a VPC, such as subnets, internet gateways and NAT gateways.
- Identify the ways to connect networks, such as VPC peering and AWS Transit Gateway.
- Distinguish security groups from network ACLs.
- Describe what VPC Flow Logs record.
VPC building blocks
An Amazon VPC is your own private network in an AWS Region, with an IP address range that you choose. It is divided into subnets, each in one Availability Zone. A public subnet has a route to an internet gateway, which connects the VPC to the internet, so it suits resources that the internet must reach, such as web servers. A private subnet has no such route, so it suits resources that should not be reachable from the internet, such as databases.
Route tables decide where traffic from each subnet goes. A NAT gateway lets resources in a private subnet start outbound connections to the internet, for example to download updates, while still blocking connections from the internet to them. The following table summarises the components.
| Component | Purpose |
|---|---|
| VPC | Your private network in a Region, with an IP range you choose |
| Subnet | A section of the VPC in one Availability Zone |
| Public subnet | Has a route to an internet gateway; for internet-facing resources such as web servers |
| Private subnet | No route to the internet gateway; for resources such as databases |
| Internet gateway | Connects the VPC to the internet |
| Route table | Decides where traffic goes |
| NAT gateway | Lets private resources make outbound internet connections (e.g. for updates) without being reachable |
The following diagram shows public and private subnets and their gateways.

VPC components
Connecting networks
As an organisation grows, its networks need to be connected. VPC peering connects two VPCs directly, so their resources can communicate privately. AWS Transit Gateway acts as a central hub that connects many VPCs and on-premises networks, which is simpler than peering every pair of VPCs. VPC endpoints let resources in a VPC reach AWS services such as S3 privately, without going over the internet. The following table summarises the options.
| Option | Connects |
|---|---|
| VPC peering | Two VPCs |
| AWS Transit Gateway | Many VPCs and on-premises networks through a central hub |
| VPC endpoints | Resources to AWS services such as S3 privately, without the internet |
Connecting networks
Security groups versus network ACLs
Security groups and network ACLs are both firewalls in a VPC, and their differences are often tested. A security group works at the level of an instance. It is stateful, so if a request is allowed in, the reply is allowed out automatically, and it contains only allow rules. A network ACL works at the level of a subnet. It is stateless, so replies must be allowed by their own rules, and it can contain deny rules, so it can block specific IP addresses. The following table summarises the differences.
Visibility and protection
AWS provides services that give visibility into network traffic and protect it. The following list describes them.
- VPC Flow Logs record IP traffic information for troubleshooting and security analysis.
- Amazon Inspector finds unintended network exposure.
- Security groups and network ACLs control which traffic may flow, as described above.
VPC visibility
A two-tier network
A company builds a VPC for a web application with a database. The layout follows a common pattern:
| Component | Configuration |
|---|---|
| Public subnets (one per AZ) | Load balancer; route to the internet gateway |
| Private subnets (one per AZ) | Web servers and the database; no direct route from the internet |
| NAT gateway | Lets private servers download updates without being reachable from outside |
| Security group: load balancer | Allows HTTPS (port 443) from anywhere |
| Security group: web servers | Allows traffic only from the load balancer's security group |
| Security group: database | Allows port 3306 only from the web servers' security group |
| Network ACL | Denies a range of IP addresses known to attack the company |
An attacker on the internet can reach only the load balancer. Even if they got past it, the database accepts connections only from the web servers. Security groups cannot deny, so blocking a specific IP range is done with the network ACL.
What is the difference between a security group and a network ACL?
Show answer
A security group works at the instance level, is stateful and has only allow rules. A network ACL works at the subnet level, is stateless and has allow and deny rules.
Exam Tips
Remember for the exam
- A stateful instance-level firewall is a security group; a stateless subnet-level firewall is a network ACL.
- To block a specific IP address, add a deny rule to a network ACL.
- Internet access for a VPC requires an internet gateway.
- For private resources that need outbound-only internet access, use a NAT gateway.
- Each subnet lives in one Availability Zone.
- To record information about network traffic, use VPC Flow Logs.