# **Launch an EC2 Instance**
1. **Go to AWS Console → EC2 → Launch Instance**
2. Select **Amazon Linux 2** (or Ubuntu/Debian, depending on preference)
3. Choose an **instance type** (e.g., t2.micro for free tier, t3.medium or higher for production)
4. Configure:
- Set **network settings in a Security Group** (allow SSH, HTTP, HTTPS)
- You need HTTP, TCP 80, Anywhere-IPv4 0.0.0.0 in this case.
- Add **storage** (default is 8GB, increase if needed)
5. **Add a key pair** (or use an existing one)
- To access the EC2 instance using ssh
```bash
ssh -i "your_keypair.pem" ec2-user@your-ec2-public-ip
```
6. Set up the **User data** in **Advanced details**
- These commands are ran after the instance is running.
```bash
#!/bin/bash
sudo dnf update -y
sudo dnf install -y nginx
sudo systemctl enable nginx
sudo systemctl start nginx
```
7. Click **Launch Instance**
# Package the launched instance as a image
1. Select the instance and click `Create image`

2. That’s all.
# Launch a new instance based on that AMI
1. Select the AMI that has been built

2. Set up the **User data** in **Advanced details**
> [!Note]
> This will be ran after the AMI is built.
>
```bash
#!/bin/bash
echo '<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Custom Web Page</title>
<style>
body { font-family: Arial, sans-serif; text-align: center; margin-top: 50px; }
h1 { color: #3498db; }
</style>
</head>
<body>
<h1>Welcome to My Custom Nginx Page!</h1>
<p>This is a modified version of the default Nginx page.</p>
</body>
</html>' | sudo tee /usr/share/nginx/html/index.html
sudo systemctl restart nginx
```