Create a Custom VPC with Public and Private Subnets

Hi there! 👋 I'm Daniel Ozoemena, a passionate Cloud Solution Architect and DevOps Engineer dedicated to building scalable, secure, and innovative cloud solutions. With hands-on experience in Azure, AWS, and Google Cloud Platform, I specialize in deploying infrastructure as code, automating workflows, and optimizing system reliability. Driven by a love for problem-solving, I constantly explore new technologies and best practices to deliver impactful results. Beyond the cloud, I enjoy mentoring, blogging about tech insights, and contributing to open-source projects. When I'm not automating deployments or creating secure virtual networks, you can find me playing chess, learning about AI, or brainstorming solutions to real-world challenges. Let’s connect and grow together on this tech journey! 🚀
Objective: Learn how to create a custom VPC, set up subnets, and configure routing.
Step 1: Create a Custom VPC
Sign in to the AWS Management Console.
Navigate to VPC Dashboard.

Click on Create VPC.
Select VPC only and click Next.
Enter the following details:
Name tag: MyCustomVPC
IPv4 CIDR block: 10.0.0.0/16
Leave other settings as default.

Click Create VPC.
Step 2: Create Public and Private Subnets
Go to Subnets (in the left panel).
Click Create Subnet.

Select MyCustomVPC from the VPC dropdown.
Create a Public Subnet
Enter:
Name tag: PublicSubnet
Availability Zone: Select any one
IPv4 CIDR block: 10.0.1.0/24

Click Create subnet.
Create a Private Subnet
Click Create Subnet again.
Enter:
Name tag: PrivateSubnet
Availability Zone: Select the same or different one
IPv4 CIDR block: 10.0.2.0/24

Click Create subnet.
Step 3: Create an Internet Gateway and Attach to the VPC
Go to Internet Gateways.
Click Create internet gateway.
Enter Name tag: MyIGW and click Create.

Select the created Internet Gateway, click Actions → Attach to VPC.

Choose MyCustomVPC and click Attach internet gateway.
Step 4: Create a Route Table for the Public Subnet
Go to Route Tables.
Click Create Route Table.
Enter:
Name tag: PublicRouteTable
VPC: Select MyCustomVPC
Click Create.

Select the created route table → Click Routes → Edit routes.
Click Add route and enter:
Destination: 0.0.0.0/0
Target: Select Internet Gateway (MyIGW)

Click Save changes.
Click Subnet Associations → Edit subnet associations.

Select PublicSubnet → Click Save.

Step 5: Create a Route Table for the Private Subnet
Repeat the steps for creating a Route Table but name it PrivateRouteTable.
No need to add a 0.0.0.0/0 route, as private subnets don’t need direct internet access.

Associate PrivateSubnet with PrivateRouteTable.
Step 6: Launch an EC2 Instance in the Public Subnet
Go to EC2 Dashboard → Launch Instance.

Choose Amazon Linux 2 as the AMI.
Select t2.micro instance type and click Next.
In Network settings:
VPC: Select MyCustomVPC
Subnet: Select PublicSubnet
Auto-assign Public IP: Enable

Click Next → Add Storage → Next.
Click Next → Configure Security Group:
Allow SSH (22) from Your IP
Allow HTTP (80) from Anywhere

Click Review and Launch → Launch.
Select/Create a key pair and launch the instance.
Step 7: Connect to the EC2 Instance
Go to Instances and select the running EC2 instance.
Copy the Public IPv4 address.
Open a terminal and connect using SSH:
bash
ssh -i my-key.pem ec2-user@<public-ip>

- You are now inside your EC2 instance! 🎉




