Sub topic 1
What a VPC is and how it is isolated
Prerequisites
This chapter assumes you know basic IP addressing and CIDR notation, such as what 10.0.0.0/16 means. You should understand TCP and UDP ports and the idea of a firewall. You also need an AWS account, a basic grasp of regions and Availability Zones, and comfort running AWS CLI commands.
The working model
A Virtual Private Cloud (VPC) is a logically isolated virtual network that you define inside one AWS region. You choose its IP address range, and you decide which resources can talk to each other and to the outside world. Nothing enters or leaves a VPC unless you configure a path for it.
Three facts shape everything else in this tutorial:
- A VPC belongs to one region and spans all Availability Zones (AZs) in that region.
- A VPC has a primary IPv4 CIDR block, from
/16(65,536 addresses) down to/28(16 addresses). - Each VPC is isolated from every other VPC by default, even inside the same account.
Subnets live inside a VPC, and each subnet sits in exactly one AZ. You launch resources such as EC2 instances into subnets. The next chapters cover subnets in detail.
How isolation works
Isolation comes from the way AWS routes packets. Your VPC has its own routing and its own address space, and AWS does not forward traffic between VPCs unless you build a connection such as peering or a Transit Gateway.
Two VPCs can even use the same CIDR block without interfering, because they never see each other. That becomes a problem only when you try to connect them, so you should plan address space early.
Inside a VPC, traffic is allowed to flow between subnets through a built-in local route. Security groups and network ACLs then decide which of that traffic is permitted.
Create a VPC
This command creates a VPC and stores its ID. The DNS hostnames setting gives instances DNS names, which later chapters use.
VPC_ID=$(aws ec2 create-vpc --cidr-block 10.0.0.0/16 --query Vpc.VpcId --output text)
aws ec2 modify-vpc-attribute --vpc-id "$VPC_ID" --enable-dns-hostnames
echo "$VPC_ID"To inspect what AWS created, run:
aws ec2 describe-vpcs --vpc-ids "$VPC_ID" --query 'Vpcs[0].[CidrBlock,State,IsDefault]' --output textThe new VPC already has a main route table with only the local route, a default network ACL, and a default security group. It has no internet gateway, so nothing in it can reach the internet yet.
Default VPC versus custom VPC
Every region in a new account includes a default VPC with 172.31.0.0/16 and public subnets. It is convenient for quick tests. For real workloads, create a custom VPC so you control the CIDR plan, subnets, and exposure.
Common errors
- Overlapping CIDRs: two VPCs with overlapping ranges cannot be peered. Choose distinct ranges from the start.
- Assuming the VPC is public: a new VPC has no internet path until you attach an internet gateway and add a route.
- Choosing a range too small: you can add secondary CIDR blocks later, but it is simpler to start with enough room.
- Forgetting regions: a VPC created in one region does not exist in another, so check your CLI region first.
Exercise
You create two VPCs in the same account and region, both with 10.0.0.0/16. Can instances in one reach instances in the other, and what stops you from peering them?
Show answer
No, they cannot reach each other, because VPCs are isolated by default and AWS forwards no traffic between them without a connection you build. Peering is blocked because the two CIDR blocks overlap, so routes could not tell which VPC an address belongs to.