A subnet is a slice of the VPC's addresses, in one availability zone. You put servers into subnets, not into the VPC itself.
VPC10.0.0.0/16
public subnet10.0.1.0/24, us-east-1a
private subnet10.0.2.0/24, us-east-1b
| Kind | Can the internet reach it? | For |
|---|---|---|
| public | yes | web servers, load balancers |
| private | no | databases, anything internal |
What makes a subnet public is a route to the internet: the next lesson. A new subnet starts private.
New command
aws ec2 create-subnet
Makes a subnet in a VPC, in one zone. The block must sit inside the VPC's.
Usageaws ec2 create-subnet --vpc-id vpc-id --cidr-block block --availability-zone zone --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=name}]'
Example
aws ec2 create-subnet --vpc-id vpc-0123456789abcdef0 --cidr-block 10.20.1.0/24 --availability-zone us-east-1a --tag-specifications 'ResourceType=subnet,Tags=[{Key=Name,Value=test-public}]'