How to Launch a Website on AWS EC2

This website is hosted on EC2 itself!

Step 1: Sign in to AWS

Go to the AWS Console and log in with your account.

Step 2: Launch EC2 Instance

Search for EC2 in the console and click Launch Instance.

Step 3: Give Your Instance a Name

Example: MyFirstWebsite.

Step 4: Choose Machine (AMI)

Select Amazon Linux 2 or Ubuntu (Free Tier eligible).

Step 5: Skip Key Pair

Choose Proceed without a key pair for now.

Step 6: Configure Security Group

Add inbound rules for HTTP (80) and HTTPS (443). Keep SSH (22) optional.

Step 7: Advanced Options → User Data

Paste this script into User Data to auto-install Apache and your site.

Step 8: Launch Instance

Click Launch and wait a few minutes.

Step 9: Copy Public IP

Open it in your browser, and 🎉 your website is live!

Interview Questions

What is EC2?

EC2 is a virtual server in the AWS cloud used to run applications and host websites.

Difference between EC2 and S3?

EC2 = Compute power. S3 = Object storage.

What is a Security Group?

A virtual firewall that controls inbound and outbound traffic.

Why use User Data in EC2?

To automate software installation and setup when the instance launches.

What happens if EC2 stops?

The instance shuts down. Data persists on EBS volume, but Public IP may change.

What is an Elastic Load Balancer (ELB)?

It automatically distributes incoming traffic across multiple EC2 instances for high availability.

Difference between Elastic IP and Public IP?

Public IP changes when the instance restarts. Elastic IP is static and can be re-mapped.

What are EC2 instance types?

Categories based on workload: General Purpose (t2/t3), Compute Optimized (c5), Memory Optimized (r5), GPU (p3), Storage Optimized (i3).

What is Auto Scaling?

A feature that automatically adds/removes EC2 instances based on demand.

Difference between Stop, Terminate, and Hibernate?

Stop = shutdown, instance can restart. Terminate = deletes instance permanently. Hibernate = saves RAM state for faster restart.