Easiest way to create an AWS VPC and EC2 instance
Create a VPC
Open the Amazon VPC console.
In the left-hand navigation pane, click on VPCs.
Click Create VPC.
Enter the following details:
Name tag: new-vpc
IPv4 CIDR block: 10.0.0.0/16
Click Create.
2. Create Subnets
In the left-hand navigation pane, click on Subnets.
Click Create subnet.
Select your new-vpc and add the following subnets one by one:
Name tag: public-key1
IPv4 CIDR block: 10.0.1.0/24
Name tag: public-key2
IPv4 CIDR block: 10.0.2.0/24
Name tag: private-key1
IPv4 CIDR block: 10.0.3.0/24
Name tag: private-key2
IPv4 CIDR block: 10.0.4.0/24
3. Create an Internet Gateway
In the left-hand navigation pane, click on Internet Gateways.
Click Create internet gateway.
Enter the Name tag: igw.
Click Create and then Attach to VPC.
Select new-vpc and click Attach internet gateway.
4. Create a NAT Gateway
In the left-hand navigation pane, click on NAT Gateways.
Click Create NAT gateway.
Select the public-key1 subnet.
Select an Elastic IP (or allocate a new one) and click Create NAT gateway.
5. Create Route Tables
Public Route Table:
In the left-hand navigation pane, click on Route Tables.
Click Create route table.
Enter the Name tag: rt-public-keys.
Select new-vpc and click Create.
Select the newly created route table and click on the Routes tab.
Click Edit routes.
Click Add route, enter 0.0.0.0/0 as the destination, and select the igw as the target.
Click Save routes.
Click on the Subnet associations tab.
Click Edit subnet associations.
Select public-key1 and public-key2 and click Save associations.
Private Route Table:
Click Create route table again.
Enter the Name tag: rt-private-keys.
Select new-vpc and click Create.
Select the newly created route table and click on the Routes tab.
Click Edit routes.
Click Add route, enter 0.0.0.0/0 as the destination, and select the NAT gateway as the target.
Click Save routes.
Click on the Subnet associations tab.
Click Edit subnet associations.
Select private-key1 and private-key2 and click Save associations.
6. Launch an EC2 Instance
Open the Amazon EC2 console.
Click Launch Instance.
Enter the Name: new-instance.
Select an Amazon Machine Image (AMI) (e.g., Amazon Linux 2).
Choose an Instance Type (e.g., t2.micro for free tier eligible).
Click Next: Configure Instance Details.
In the Network section, select new-vpc.
In the Subnet section, select public-key1.
Enable Auto-assign Public IP.
Click Next: Add Storage (you can use the default settings here).
Click Next: Add Tags (you can add additional tags if needed).
Click Next: Configure Security Group.
Create a new security group:
Security group name: sg-1
Add rules for:
SSH: Source 0.0.0.0/0
HTTP: Source 0.0.0.0/0
HTTPS: Source 0.0.0.0/0
Launch the EC2 Instance:
After reviewing all the settings, click the Launch button on the EC2 console.
Select or create a new key pair if you haven’t already, then click Launch Instances.
2. Check the Status of Your Instance:
Go to the Instances section in the EC2 dashboard.
Wait until the instance state changes to running and the status checks show 2/2 checks passed.
3. Get the Public IP Address:
Select your running instance from the list.
In the instance description, find the Public IPv4 address. This is the IP address you’ll use to access your web server.
4. Open the Web Page:
Copy the Public IP address.
Open a new browser tab and enter the Public IP address into the address bar.
ipv4