Hosting a Full-Stack React App on AWS: A Beginner’s Guide (EC2 & EKS)

Deploying your full-stack JavaScript/React app on AWS can seem intimidating at first—but it doesn’t have to be. This beginner-friendly guide introduces AWS, outlines its main hosting options, and then walks you through deploying your React frontend and Node.js backend using EC2 and EKS.

What is AWS?

Amazon Web Services (AWS) is a cloud computing platform that provides servers, storage, networking, and tools to help you deploy applications without managing physical infrastructure. Whether you’re building a hobby app or launching a SaaS startup, AWS scales with your needs.

Think of AWS as renting computing power instead of owning a data center.


Hosting Options on AWS (Quick Comparison)

ServiceIdeal ForProsCons
EC2Custom server setupFull controlManual setup & scaling
EKSContainerized microservicesKubernetes orchestrationComplex to configure
AmplifyStatic & serverless appsEasy CI/CD & hostingLimited backend control
Elastic BeanstalkSimple Node appsAuto handles infraLess granular control
LightsailSmall predictable appsFixed pricing & simplicityNot as scalable

In this article, we’ll dive into EC2 (low-level control) and EKS (scalable Kubernetes-based orchestration).


Deploying a Full-Stack App on EC2 (Step-by-Step)

1. Launch an EC2 Instance

  • Go to EC2 on AWS Console
  • Choose Ubuntu (or Amazon Linux)
  • Pick a type (t2.micro is free-tier eligible)
  • Allow inbound ports: 22 (SSH), 80 (HTTP)
  • Create a key pair (for SSH access)

2. SSH into Your Server

ssh -i your-key.pem ubuntu@<your-ec2-public-ip>

3. Install Software

sudo apt update
sudo apt install -y nodejs npm nginx git

4. Deploy Backend

git clone https://github.com/your-user/your-app.git
cd your-app/backend
npm install
npm start

5. Configure Nginx for the API

server {
  listen 80;
  location /api/ {
    proxy_pass http://localhost:3000;
    proxy_set_header Host $host;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection 'upgrade';
  }
}

6. Deploy Frontend

cd ../frontend
npm run build
sudo cp -r build/* /var/www/html/

Update Nginx:

location / {
  root /var/www/html;
  index index.html;
  try_files $uri /index.html;
}

Now your app is live at your EC2’s public IP.


Containerized Deployment with EKS

1. Dockerize Your App

Backend Dockerfile:

FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 4000
CMD ["npm", "start"]

Frontend Dockerfile (optional if separate):

FROM node:18-alpine
WORKDIR /app
COPY . .
RUN npm install && npm run build
RUN npm install -g serve
EXPOSE 3000
CMD ["serve", "-s", "build"]

2. Push to ECR

eval $(aws ecr get-login-password --region us-east-1)
docker tag your-image:latest <aws-account-id>.dkr.ecr.us-east-1.amazonaws.com/your-repo

3. Create EKS Cluster

eksctl create cluster --name my-app --region us-east-1 --nodes 2

4. Deploy with kubectl

kubectl create deployment backend --image=<image-url>
kubectl expose deployment backend --type=LoadBalancer --port=80 --target-port=4000

5. Access the App

Use:

kubectl get services

Look for the EXTERNAL-IP — that’s your app’s public URL!


EC2 vs EKS — Which to Choose?

ScenarioUse This
Simple, low-traffic projectEC2
Need tight control over the serverEC2
Auto-scaling containers/microservicesEKS
Plan to scale and automate deploymentsEKS

Further Reading


Ready to bring your app online? Start with EC2 if you want to learn the nuts and bolts. Move to EKS when you’re ready for automation and scale.