Overview
Amazon EC2 (Elastic Compute Cloud) lets you rent virtual servers in the cloud. In this project you will launch a Linux instance, connect to it over SSH, install a web server, and serve a simple HTML page to the internet.
What You Will Learn
- Launching an EC2 instance from the AWS Console
- Understanding instance types and AMIs (Amazon Machine Images)
- Configuring Security Groups to control inbound traffic
- Connecting to a Linux server via SSH using a key pair
- Installing and running a web server (Nginx)
Prerequisites
- An AWS account (free tier
t2.micro/t3.microis sufficient) - A terminal with SSH support (macOS/Linux built-in, or Windows Terminal / PuTTY on Windows)
Architecture
Your Browser → Internet → Security Group (port 80) → EC2 Instance (Nginx)
Your Terminal → Internet → Security Group (port 22) → EC2 Instance (SSH)
Steps
1. Create a Key Pair
Before launching an instance you need a key pair to authenticate over SSH.
- In the AWS Console, navigate to EC2 → Key Pairs (under Network & Security).
- Click Create key pair.
- Name it
my-ec2-key, choose RSA and .pem format. - Click Create key pair — the
.pemfile downloads automatically. Keep it safe.
On macOS/Linux, restrict the file permissions so SSH accepts it:
chmod 400 ~/Downloads/my-ec2-key.pem
2. Launch an EC2 Instance
- Navigate to EC2 → Instances → Launch instances.
- Fill in the details:
- Name:
my-first-server - AMI: Amazon Linux 2023 (free tier eligible)
- Instance type:
t2.microort3.micro(free tier eligible) - Key pair: select
my-ec2-key
- Name:
- Under Network settings, click Edit and add two inbound rules to the security group:
Type Protocol Port Source SSH TCP 22 My IP HTTP TCP 80 0.0.0.0/0 - Leave storage at the default 8 GiB.
- Click Launch instance.
3. Connect via SSH
Wait about 30 seconds for the instance to reach the Running state, then:
- Select your instance and click Connect → copy the SSH command, or build it manually:
ssh -i ~/Downloads/my-ec2-key.pem ec2-user@<YOUR_PUBLIC_IP>
Replace <YOUR_PUBLIC_IP> with the Public IPv4 address shown in the instance details.
You should land at the Amazon Linux shell prompt.
4. Install Nginx and Serve a Web Page
Run the following commands inside the SSH session:
# Update packages
sudo dnf update -y
# Install Nginx
sudo dnf install nginx -y
# Start Nginx and enable it on boot
sudo systemctl start nginx
sudo systemctl enable nginx
# Replace the default welcome page
echo "<h1>Hello from my EC2 instance!</h1>" | sudo tee /usr/share/nginx/html/index.html
5. View Your Web Page
Open a browser and navigate to:
http://<YOUR_PUBLIC_IP>
You should see Hello from my EC2 instance!
Clean Up
EC2 instances accrue charges while running. When you are done:
- Select the instance → Instance state → Terminate instance.
- Optionally delete the key pair and security group.
Stopping an instance pauses the hourly compute charge but the root EBS volume still incurs storage costs. Terminating removes everything.
Going Further
- Automate setup with User Data scripts (runs on first boot).
- Assign an Elastic IP so your public address does not change on restart.
- Put an Application Load Balancer in front of multiple instances for high availability.
- Use AWS Systems Manager Session Manager to connect without opening port 22.