Here’s a diagram of what we’ll build:


1. Go to Internet Gateways > Create Internet Gateway.
2. Name it
3. Click Create Internet Gateway.


If the connection succeeds, our public subnet works perfectly.
Step 1: Create a Custom VPC
First, we create a Virtual Private Cloud (VPC). This is our own private space inside AWS.- Open the AWS Management Console.
- Navigate to VPC > Your VPCs > Create VPC.
- Choose VPC only.
- Name it
MyCustomVPC
. - Set the IPv4 CIDR block to
10.100.0.0/16
. - Leave IPv6 and Tenancy settings at default.
- Click Create VPC.
Step 2: Create an Internet Gateway
A public subnet must have a door to the outside world. The internet gateway (IGW) acts as that door.1. Go to Internet Gateways > Create Internet Gateway.
2. Name it
MyInternetGateway
.3. Click Create Internet Gateway.
5. Select the new IGW, then click Actions > Attach to VPC.
6. Choose
6. Choose
MyCustomVPC
.Our VPC can now connect to the internet, but it still needs a path.

Step 3: Create the Subnet
Next, we carve a small piece of our VPC to use as a public subnet.- Go to Subnets > Create Subnet.
- Select
MyCustomVPC
. - Name it
MyPublicSubnet
. - Choose a Availability Zone (for example,
eu-central-1a
). - Set the CIDR block to
10.100.1.0/24
. - Click Create Subnet.
This subnet is ready but cannot talk to the internet yet.

Step 4: Create a Route Table and Add the Route
A route table guides traffic inside our VPC. We must create one and tell it how to reach the internet.- Go to Route Tables > Create Route Table.
- Name it
MyPublicRouteTable
. - Select
MyCustomVPC
. - Click Create Route Table.
Now we add a route:

- Select
MyPublicRouteTable
. - Go to the Routes tab.
- Click Edit routes > Add route.
- Destination:
0.0.0.0/0
. - Target: Select Internet Gateway and choose
MyInternetGateway
. - Save changes.
Lastly, we associate the route table with our subnet:

- Go to the Subnet Associations tab.
- Click Edit subnet associations.
- Select
MyPublicSubnet
. - Save changes.
Our public subnet can now reach the internet.
Step 5: Test It - Launch an EC2 Instance
We test our setup by launching a small EC2 instance.- Go to EC2 > Instances > Launch Instance.
- Name the instance
EC2-PUBLIC
. - Choose an Amazon Linux 2 AMI.
- Instance type:
t2.micro
. - Key pair: Create or select an existing one.
- Under Network settings, choose
MyCustomVPC
. - Subnet: Choose
MyPublicSubnet
. - Auto-assign Public IP: Enable.
- Security group: Create one that allows SSH (port 22) from your IP.
- Launch the instance.
ssh -i your-key.pem ec2-user@your-instance-public-ip