How to create a Public Subnet in AWS


A strong foundation is key to building anything in the cloud. In this post, we will create a public subnet in AWS. We will build a custom VPC, connect it to the internet, and test it by launching an EC2 instance.

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


Step 1: Create a Custom VPC

First, we create a Virtual Private Cloud (VPC). This is our own private space inside AWS.
  1. Open the AWS Management Console.
  2. Navigate to VPC > Your VPCs > Create VPC.
  3. Choose VPC only.
  4. Name it MyCustomVPC.
  5. Set the IPv4 CIDR block to 10.100.0.0/16.
  6. Leave IPv6 and Tenancy settings at default.
  7. 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 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.
  1. Go to Subnets > Create Subnet.
  2. Select MyCustomVPC.
  3. Name it MyPublicSubnet.
  4. Choose a Availability Zone (for example, eu-central-1a).
  5. Set the CIDR block to 10.100.1.0/24.
  6. 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.
  1. Go to Route Tables > Create Route Table.
  2. Name it MyPublicRouteTable.
  3. Select MyCustomVPC.
  4. Click Create Route Table.


Now we add a route:
  1. Select MyPublicRouteTable.
  2. Go to the Routes tab.
  3. Click Edit routes > Add route.
  4. Destination: 0.0.0.0/0.
  5. Target: Select Internet Gateway and choose MyInternetGateway.
  6. Save changes.



Lastly, we associate the route table with our subnet:
  1. Go to the Subnet Associations tab.
  2. Click Edit subnet associations.
  3. Select MyPublicSubnet.
  4. 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.
  1. Go to EC2 > Instances > Launch Instance.
  2. Name the instance EC2-PUBLIC.
  3. Choose an Amazon Linux 2 AMI.
  4. Instance type: t2.micro.
  5. Key pair: Create or select an existing one.
  6. Under Network settings, choose MyCustomVPC.
  7. Subnet: Choose MyPublicSubnet.
  8. Auto-assign Public IP: Enable.
  9. Security group: Create one that allows SSH (port 22) from your IP.
  10. Launch the instance.
When it is running, copy its public IP address. Open a terminal and connect:

ssh -i your-key.pem ec2-user@your-instance-public-ip

If the connection succeeds, our public subnet works perfectly.


Previous Post Next Post