</>
Skip to content
AWS lessons (26/47)

AWS — VPC

What is VPC?

Virtual Private Cloud provides isolated network infrastructure.

Create VPC

aws ec2 create-vpc --cidr-block 10.0.0.0/16

Subnets

# Public subnet
aws ec2 create-subnet \
  --vpc-id vpc-12345678 \
  --cidr-block 10.0.1.0/24 \
  --availability-zone us-east-1a

# Private subnet
aws ec2 create-subnet \
  --vpc-id vpc-12345678 \
  --cidr-block 10.0.2.0/24 \
  --availability-zone us-east-1a

Internet gateway

# Create
aws ec2 create-internet-gateway

# Attach to VPC
aws ec2 attach-internet-gateway \
  --internet-gateway-id igw-12345678 \
  --vpc-id vpc-12345678

Route tables

# Create route table
aws ec2 create-route-table --vpc-id vpc-12345678

# Add route to internet
aws ec2 create-route \
  --route-table-id rtb-12345678 \
  --destination-cidr-block 0.0.0.0/0 \
  --gateway-id igw-12345678

NAT gateway

# Allocate Elastic IP
aws ec2 allocate-address

# Create NAT gateway
aws ec2 create-nat-gateway \
  --subnet-id subnet-12345678 \
  --allocation-id eipalloc-12345678

Security groups

# Create
aws ec2 create-security-group \
  --group-name my-sg \
  --description "My SG" \
  --vpc-id vpc-12345678

# Add rules
aws ec2 authorize-security-group-ingress \
  --group-id sg-12345678 \
  --protocol tcp \
  --port 80 \
  --cidr 0.0.0.0/0

Network ACLs

# Create NACL
aws ec2 create-network-acl --vpc-id vpc-12345678

# Add rule
aws ec2 create-network-acl-entry \
  --network-acl-id acl-12345678 \
  --rule-number 100 \
  --protocol tcp \
  --port-range From=80,To=80 \
  --rule-action allow \
  --egress

Mini Practice

  1. Create a VPC with subnets
  2. Set up internet gateway
  3. Configure security groups
  4. Create a NAT gateway

Up Next

Continue with CloudFront - Content Delivery Network.

Related Topics

Frequently Asked Questions about VPC

What is VPC in AWS?

VPC is a fundamental concept in AWS. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn VPC?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn VPC.

Why is VPC important in AWS?

VPC is essential for AWS development. Understanding this concept will help you write better code and solve real-world problems more effectively.