A Guide to Deploying Full-Stack Apps on AWS EC2
A Guide to Deploying Full-Stack Apps on AWS EC2
While platform-as-a-service (PaaS) providers like Vercel and Heroku are incredibly convenient, understanding how to deploy applications on bare-metal virtual machines like AWS EC2 is a crucial skill for any backend engineer.
Step 1: Provisioning the Instance
- Navigate to the EC2 Dashboard in the AWS Management Console.
- Click Launch Instance.
- Choose an Amazon Machine Image (AMI). I prefer Ubuntu Server 24.04 LTS.
- Select your instance type (a
t3.microis fine for testing). - Configure your Security Group to allow inbound traffic on ports
22(SSH),80(HTTP), and443(HTTPS).
Step 2: Server Setup
SSH into your new instance:
ssh -i "your-key.pem" ubuntu@your-instance-ip
Update your packages and install the necessary dependencies (Node.js, Python, Docker, Nginx, etc.):
sudo apt update && sudo apt upgrade -y
sudo apt install nginx -y
Step 3: Setting up a Reverse Proxy
Nginx acts as a reverse proxy, taking requests on port 80 and forwarding them to your application running on a local port (like 3000 or 8000).
Edit your Nginx config:
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://localhost:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
Conclusion
Managing your own EC2 instances gives you unparalleled control over your infrastructure and costs, a critical component of building scalable systems.