AWS Builder Center
Building a Highly Available 3-Tier Web Application on AWS with VPC, EC2, Load Balancers, and Amazon Aurora

Building a Highly Available 3-Tier Web Application on AWS with VPC, EC2, Load Balancers, and Amazon Aurora

Author: Vishal Patil Project Manager: Ulhas Narwade Tags: AWS, VPC, EC2, Elastic Load Balancing, Amazon Aurora, Nginx, React, High Availability #vishalcloudjourney

Aspiring Cloud & DevOps Engineer | AWS | Linux | Cloud Automation

Introduction

Early in my AWS learning, I practiced with single services: an EC2 instance here, an S3 bucket there. These taught me the basics, but not how real applications are built. Production systems are layered, with clear security boundaries and a plan for failure.
So I built a 3-tier web application on AWS from scratch, with a web tier, an application tier, and a database tier. Each tier has its own subnets and security rules, and everything is spread across two Availability Zones so that one data center failing doesn’t take the app down.

What Is a 3-Tier Architecture?

Tier
Responsibility
Network placement
Web
Serves the React UI, forwards API calls
Public subnets
Application
Business logic, database access
Private subnets
Database
Persistent data storage
Private subnets
Why use it?
  • Only the web tier faces the internet.
  • Each tier scales independently.
  • You can update one layer without touching the others.
  • A failure in one layer stays contained.

Architecture Overview

  • A custom VPC across two Availability Zones (AZ1 and AZ2)
  • An Internet Gateway for internet connectivity
  • An external Application Load Balancer for user traffic
  • Web tier: two EC2 instances in public subnets, one per AZ
  • An internal Application Load Balancer between the web and app tiers
  • App tier: two EC2 instances in private subnets, one per AZ
  • Database tier: an Amazon Aurora primary (writer) in one AZ and a Read Replica in the other, both in private subnets
  • A NAT Gateway so private instances can download packages without being exposed

Traffic flow

  1. The user opens the external load balancer’s DNS name.
  1. The request passes through the Internet Gateway to the external ALB.
  1. The ALB forwards it to a healthy web tier instance.
  1. Nginx serves the React UI and proxies API calls to the internal ALB.
  1. The internal ALB routes them to a healthy app tier instance.
  1. The app tier reads from and writes to Aurora.
  1. The response returns along the same path.
I built everything in the Asia Pacific (Mumbai)  ap-south-1  region.

Step 1: Create the Network

  • VPC: a custom VPC with a CIDR block such as  10.0.0.0/16 .
  • Subnets: six in total, two per tier, one in each AZ (two public for web, two private for app, two private for database). Clear names like  web-public-1a  and  app-private-1a  saved a lot of confusion later.
  • Internet Gateway: attached to the VPC.
  • Public route table: sends  0.0.0.0/0  to the Internet Gateway and is associated with the public subnets.
  • NAT Gateway: placed in a public subnet with an Elastic IP.
  • Private route table: sends  0.0.0.0/0  to the NAT Gateway and is associated with the private subnets.

Step 2: Configure Security Groups

I chained security groups so each tier only accepts traffic from the tier in front of it, instead of opening IP ranges.
Security group
Inbound rule
Source
External ALB SG
HTTP 80
Anywhere
Web tier SG
HTTP 80
External ALB SG
Internal ALB SG
HTTP 80
Web tier SG
App tier SG
App port (e.g. 3200)
Internal ALB SG
Database SG
3306
App tier SG
For administration, I allowed SSH from my own IP on the web tier and used it as a jump host to reach the private instances. In production, use AWS Systems Manager Session Manager instead.

Step 3: Build the Database Tier

  1. Created a DB subnet group with the two private database subnets.
  1. Launched an Aurora (MySQL-compatible) cluster with a writer in AZ1 and a reader in AZ2, using the database security group, with public access set to No.
  1. From an app instance, connected to the writer endpoint and created the schema:
sql
CREATE DATABASE webappdb;
USE webappdb;

CREATE TABLE transactions (
id INT NOT NULL AUTO_INCREMENT,
amount DECIMAL(10,2),
description VARCHAR(100),
PRIMARY KEY (id)
);
Aurora replicates its storage across AZs, and the read replica adds read capacity and a failover target.

Step 4: Build the Application Tier

I launched two EC2 instances (Amazon Linux) in the private app subnets and installed the tooling:
bash
sudo yum update -y
sudo yum install mysql -y
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 16
npm install -g pm2
I set the database details in the backend config (placeholders shown, never publish real credentials):
javascript
module.exports = {
DB_HOST: '<aurora-writer-endpoint>',
DB_USER: '<db-username>',
DB_PWD: '<db-password>',
DB_DATABASE: 'webappdb'
};
Then I started the service with PM2, which restarts it after crashes and reboots:
bash
cd ~/app-tier && npm install
pm2 start index.js
pm2 startup && pm2 save
curl http://localhost:3200/health
Next I created a target group with a  /health  check, registered both instances, and created the internal ALB across the private app subnets. Its DNS name gives the web tier one stable address for the app tier.

Step 5: Build the Web Tier

On two EC2 instances in the public subnets, I installed Node.js, built the React app, and installed Nginx:
bash
cd ~/web-tier
npm install && npm run build
sudo amazon-linux-extras install nginx1 -y
Nginx serves the React build and acts as a reverse proxy to the internal load balancer:
nginx
server {
listen 80;
location / {
root /home/ec2-user/web-tier/build;
index index.html;
try_files $uri /index.html;
}
location /api/ {
proxy_pass http://<internal-alb-dns-name>:80/;
}
}
bash
sudo nginx -t
sudo systemctl restart nginx
sudo systemctl enable nginx
Finally, I created a web target group (health check on  / ), registered both instances, and created the internet-facing ALB across the public subnets.

Step 6: Test the Application

I opened the external load balancer’s DNS name.
  • Home page: “AWS 3-TIER WEB APP DEMO” loaded with the architecture diagram, confirming the web tier and external ALB worked.
  • Database page: The “AURORA DATABASE DEMO PAGE” listed records with ID, Amount, and Description, plus ADD and DEL buttons. I added a record, refreshed, and it persisted.
That one page proved the full chain: browser, external ALB, web tier, internal ALB, app tier, Aurora.

High Availability in Practice

  • An instance fails: health checks remove it from rotation and the other instance serves users.
  • An entire AZ fails: each tier has an instance in the second AZ, so traffic continues there.
  • The Aurora primary fails: the read replica can be promoted to writer.
To see it yourself, stop one web instance and keep refreshing the page. The site stays up.

Challenges and Fixes

  1. Unhealthy targets: a wrong health check path and a missing security group rule. I fixed the path, port, and security group, in that order.
  1. 403 Forbidden from Nginx: Nginx couldn’t read the build folder in the home directory. Correcting permissions and the  root  path fixed it.
  1. Frontend couldn’t reach the backend:  proxy_pass  pointed to the wrong address. Using the internal ALB DNS name fixed it.
  1. Database connection errors: a wrong endpoint and a missing rule for port 3306 from the app tier SG.
My best debugging habit: test one tier at a time, bottom up. Check the database, then the app with  curl , then the internal ALB, then the web tier, then the external ALB.

Key Learnings

  • Security by design: only the web tier is public, and chained security groups limit each tier’s trust.
  • Load balancers do more than distribute traffic: their health checks are the basis of self-healing.
  • Subnet and route table design prevents most networking headaches.
  • Nginx as a reverse proxy gives the browser a single endpoint while traffic routes internally.
  • PM2 keeps backend services alive.
  • Secrets don’t belong in code: use Secrets Manager or Parameter Store in production.

Cost and Clean-Up

Delete resources in this order to avoid surprise charges:
  1. Both load balancers and target groups
  1. EC2 instances
  1. The Aurora cluster (reader first, then writer)
  1. The NAT Gateway, then release its Elastic IP
  1. Subnets, route tables, Internet Gateway, security groups, and finally the VPC
The NAT Gateway, Aurora, and load balancers cost the most, so set up an AWS Budget alert before starting.

What’s Next

  • Auto Scaling Groups for the web and app tiers
  • HTTPS with AWS Certificate Manager
  • Route 53 for a friendly domain name
  • AWS WAF in front of the external ALB
  • CloudWatch dashboards and alarms
  • CloudFormation or Terraform to automate the whole build

Conclusion

Studying VPC, EC2, ELB, security groups, and Aurora separately gave me pieces of a puzzle. Wiring them into one working system showed me how they depend on each other and why networking, security, and availability decisions matter. When the demo page loaded through the load balancer and the Aurora page showed my records, it was one of the most satisfying moments of my cloud journey so far.
If you’re learning AWS, build a project like this end to end. You’ll learn more from debugging it than from any slide deck.

Acknowledgement

This project was completed under the guidance of my project manager, Ulhas Narwade Sir. His direction, reviews, and support helped me understand how a real-world 3-tier architecture is planned, built, and tested on AWS. I am grateful for the opportunity and everything I learned.


Written by: Vishal Patil Project Manager: Ulhas Narwade
Connect with me:
#vishalcloudjourney #AWS #3TierArchitecture #AmazonAurora #ElasticLoadBalancing #VPC #CloudComputing
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article