Creating a VPC with Public and Private Subnets

Creating a VPC with Public and Private Subnets is a fundamental AWS networking lab that helps to understand how to isolate resources within a Virtual Private Cloud (VPC) and manage their access to the internet.

Summary:

  • Create a VPC
  • Create Subnets
  • Create and Attach an Internet Gateway
  • Create Route Tables
  • Launch an EC2 Instance in the Public Subnet
  • Access the EC2 Instance

Step 1: Create a VPC

  • Search VPC
  • Click on Create VPC.
  • Provide a Lab-vpc for VPC.
  • Select an IPv4 CIDR block (e.g., 10.0.0.0/24).
  • Click Create VPC.

Image description

Step 2: Create Subnets

Create a Public Subnet:

  • Select Subnets on the left panel and click Create subnet.
  • Select the VPC you created earlier.
  • Provide a Public-subnet for the subnet.
  • Specify an Availability Zone (us-east-1a)
  • Set the IPv4 CIDR block ( 10.0.0.0/25).
  • Click Create Subnet.

Create a Private Subnet:

  • Repeat the steps to create another subnet within the same VPC.
  • Name this subnet (Private-Subnet.)
  • IPv4 CIDR block (e.g., 10.0.0.128/25).
  • Click Create Subnet.

Image description

Step 3: Create and Attach an Internet Gateway

Create an Internet Gateway (IGW):

  • In the VPC Dashboard, click on Internet Gateways and then Create Internet Gateway.
  • Provide a VPC-Internet-gateway for the IGW.
  • Click Create Internet Gateway.

Attach the Internet Gateway to Your VPC:

  • After creation, select the newly created IGW.
  • Click Actions and choose Attach to VPC.
  • Select the VPC you created and click Attach Internet Gateway.

Step 4: Create Route Tables

Create a Public Route Table:

  • Go to Route Tables on the left panel and click Create route table.
  • Name it Public-Route-Table.
  • Select the VPC which created earlier.
  • Click Create.

Add a Route for the Internet Gateway:

  • Select the Public-Route-Table.
  • Under Routes, click Edit routes.

Add a new route:

  • Destination: 0.0.0.0/0
  • Target: Select your Internet Gateway (IGW) from the dropdown.
  • Click Save routes.

Associate Public Subnet with the Public Route Table:

  • Under the Subnet associations tab, click Edit subnet associations.
  • Select your Public-Subnet and click Save associations.
  • Repeat this process for private subnets.

Step 5: Launch an EC2 Instance in the Public Subnet

Launch a New EC2 Instance:

  • Click on Launch Instance.
  • Select an Amazon Linux 2.
  • Choose an instance type (t2.micro)
  • Under Network, choose the VPC you created.
  • Under Subnet, select Public-Subnet.
  • Ensure Auto-assign Public IP is enabled.
  • Configure the security group to allow HTTP traffic.
  • Click advance details and add website code in the user data.
  • Review and launch the instance.

Image description

Step 6: Access the EC2 Instance

  • Copy the Public IPv4 address and paste it on new tab.
  • click on the Ip and remove ‘s’ from https to http.

Image description


Discover more from Coursity

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

Discover more from Coursity

Subscribe now to keep reading and get access to the full archive.

Continue reading

Scroll to Top