sudo apt update
sudo apt install awscli -yRun this command and enter 4 things:
aws configureYou'll be prompted for:
| Prompt | Where to find it |
|---|---|
| AWS Access Key ID | AWS Console → Account name (top right) → Security credentials → Access keys → Create access key |
| AWS Secret Access Key | Shown ONCE when you create the key — download the .csv file immediately |
| Default region | e.g. us-east-2 (check your AWS console URL for your region) |
| Default output format | Just press Enter (defaults to json) |
IMPORTANT: Never share your keys or push them to GitHub.
When creating an EC2 instance, AWS gives you a .pem file (your SSH key). Move it to a safe location:
# Copy from Windows Downloads to WSL SSH folder
cp /mnt/c/Users/YOUR_USERNAME/Downloads/your-key.pem ~/.ssh/
# Lock down permissions (SSH requires this)
chmod 400 ~/.ssh/your-key.pemssh -i ~/.ssh/your-key.pem ubuntu@YOUR_PUBLIC_IPUsername depends on AMI:
- Ubuntu →
ubuntu - Amazon Linux →
ec2-user - Debian →
admin
Your website won't load without this. In the AWS Console:
- EC2 → your instance → Security tab
- Click the security group
- Edit inbound rules
- Add rule: Type = HTTP, Port = 80, Source = 0.0.0.0/0
Paste these into the User Data field under Advanced Details when launching an EC2 instance.
- Next.js / Node.js app from GitHub → see
scripts/nextjs-ubuntu.sh - Static HTML website (no repo needed) → see
scripts/static-nginx-ubuntu.sh - Any public repo (React/Vite) → see
scripts/react-ubuntu.sh
# List all instances with ID, status, and IP
aws ec2 describe-instances --region us-east-2 \
--query "Reservations[*].Instances[*].[InstanceId,State.Name,PublicIpAddress]" \
--output table
# Stop an instance
aws ec2 stop-instances --instance-ids i-XXXXX --region us-east-2
# Start an instance
aws ec2 start-instances --instance-ids i-XXXXX --region us-east-2
# Terminate (permanently delete) an instance
aws ec2 terminate-instances --instance-ids i-XXXXX --region us-east-2Edit ~/.ssh/config to avoid typing the full SSH command every time:
Host myserver
HostName YOUR_PUBLIC_IP
User ubuntu
IdentityFile ~/.ssh/your-key.pem
Then just type:
ssh myserver- AMI selected (Ubuntu or Amazon Linux)
- Key pair selected (existing or new)
- User Data script pasted in Advanced Details
- Security Group allows HTTP (port 80) from 0.0.0.0/0
- After launch, wait 2-3 minutes for script to finish
- Visit http://YOUR_PUBLIC_IP (not https)
# Check if the startup script ran successfully
cat /var/log/cloud-init-output.log
# Check if app is running (Node.js apps)
pm2 list
# Check if build folder exists (Next.js)
ls /var/www/mysite/.next
# Check available memory
free -m
# If build fails due to low memory, add swap:
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile