DEV Community

Cover image for Day 27.Configuring a Public VPC with an EC2 Instance for Internet Access
Thu Kha Kyawe
Thu Kha Kyawe

Posted on

Day 27.Configuring a Public VPC with an EC2 Instance for Internet Access

Lab Information

The Nautilus DevOps Team has received a request from the Networking Team to set up a new public VPC to support a set of public-facing services. This VPC will host various resources that need to be accessible over the internet. As part of this setup, you need to ensure the VPC has public subnets with automatic IP assignment for resources. Additionally, a new EC2 instance will be launched within this VPC to host public applications that require SSH access. This setup will enable the Networking Team to deploy and manage public-facing applications.

Create a public VPC named xfusion-pub-vpc, and a subnet named xfusion-pub-subnet under the same, make sure public IP is being auto assigned to resources under this subnet. Further, create an EC2 instance named xfusion-pub-ec2 under this VPC with instance type t2.micro. Make sure SSH port 22 is open for this instance and accessible over the internet.

Lab Solutions

πŸ”Ή STEP 1: Create the Public VPC

Go to AWS Console β†’ VPC

Click Create VPC

Select VPC only

Configure:

Name: xfusion-pub-vpc

IPv4 CIDR block: 10.0.0.0/16

Tenancy: Default

Click Create VPC

πŸ”Ή STEP 2: Create the Public Subnet

In VPC β†’ Subnets

Click Create subnet

Configure:

VPC: xfusion-pub-vpc

Subnet name: xfusion-pub-subnet

Availability Zone: any (e.g., us-east-1a)

IPv4 CIDR: 10.0.1.0/24

Click Create subnet

πŸ”Ή STEP 3: Enable Auto-Assign Public IP on Subnet (VERY IMPORTANT)

Select xfusion-pub-subnet

Click Actions β†’ Edit subnet settings

Enable:

βœ… Auto-assign public IPv4 address

Click Save

This ensures all EC2 instances launched in this subnet get a public IP automatically.

πŸ”Ή STEP 4: Create & Attach Internet Gateway
4.1 Create Internet Gateway

VPC β†’ Internet Gateways

Click Create internet gateway

Name: xfusion-pub-igw

Click Create

4.2 Attach Internet Gateway to VPC

Select xfusion-pub-igw

Click Actions β†’ Attach to VPC

Select xfusion-pub-vpc

Click Attach

πŸ”Ή STEP 5: Configure Route Table for Internet Access

Go to VPC β†’ Route Tables

Select the route table associated with xfusion-pub-vpc

Click Edit routes

Add route:

Destination: 0.0.0.0/0

Target: Internet Gateway (xfusion-pub-igw)

Save changes

Associate Route Table with Subnet

Go to Subnet associations

Click Edit subnet associations

Select xfusion-pub-subnet

Save

πŸ”Ή STEP 6: Launch EC2 Instance in Public VPC

Go to EC2 β†’ Launch instance

Configure:

Instance details

Name: xfusion-pub-ec2

AMI: Amazon Linux or Ubuntu

Instance type: t2.micro

Network settings

VPC: xfusion-pub-vpc

Subnet: xfusion-pub-subnet

Auto-assign public IP: Enabled

Security Group (IMPORTANT)

Create a new security group:

Name: xfusion-pub-sg

Inbound rules:

Type Port Source
SSH 22 0.0.0.0/0

Outbound: Allow all

Launch the instance

πŸ”Ή STEP 7: Verify Internet & SSH Access

Wait for:

Instance state: Running

Status checks: 2/2 passed

Select xfusion-pub-ec2

Confirm:

Public IPv4 address exists


Resources & Next Steps
πŸ“¦ Full Code Repository: KodeKloud Learning Labs
πŸ“– More Deep Dives: Whispering Cloud Insights - Read other technical articles
πŸ’¬ Join Discussion: DEV Community - Share your thoughts and questions
πŸ’Ό Let's Connect: LinkedIn - I'd love to connect with you

Credits
β€’ All labs are from: KodeKloud
β€’ I sincerely appreciate your provision of these valuable resources.

Top comments (0)