How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3

In this article, we will cover how to Set Up a 3-tier Architecture on AWS with EC2, RDS, and S3.

A 3-tier architecture is a well-established software pattern that separates the user interface, business logic, and data layers, offering scalability, maintainability, and security. In this article, we will build a robust 3-tier architecture on AWS using various services including VPC, EC2, IAM, S3, RDS, AWS Certificate Manager, and Route 53.

Prerequisites

To set up a 3-tier architecture on AWS, you need:

  • An AWS account with necessary permissions
  • A registered domain name (for Route 53 and HTTPS)
  • A VPC with public and private subnets
  • An Internet Gateway and routing configured
  • A key pair to access EC2 instances
  • Security groups to control traffic between layers
  • An SSL certificate via AWS Certificate Manager (ACM)
  • An RDS database instance (e.g., Aurora or MySQL)
  • An S3 bucket (optional, for static assets or backups)
  • A Route 53 hosted zone for DNS resolution

Overview of the 3-Tier Architecture

The architecture is divided into the following layers:

  • Web Tier: Handles incoming traffic and serves the front-end.
  • App Tier: Contains the business logic of the application.
  • Database Tier: Manages persistent data storage.

We will implement this architecture using the following AWS services:

  • Amazon VPC: To create isolated network environments.
  • Amazon EC2: To host web and app servers.
  • Amazon RDS (Aurora): For managed relational database services.
  • IAM: To manage access and permissions.
  • Amazon S3: For storing static assets.
  • AWS Certificate Manager (ACM): To manage SSL/TLS certificates.
  • Amazon Route 53: For DNS management and domain routing.

Architecture Diagram

Below is the visual representation of our 3-tier architecture:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 1

1.Web Tier (Presentation Layer)

Components:

  • Public Subnets in 2 Availability Zones for high availability.
  • EC2 Instances acting as web servers.
  • Elastic Load Balancer (ELB) for distributing traffic across instances.
  • Internet Gateway for internet access.
  • Route 53 to manage the domain and route traffic.
  • Certificate Manager to provide HTTPS via an SSL certificate.

Features:

  • Secure access using HTTPS (managed by ACM).
  • Static files (CSS, JS, images) can be offloaded to Amazon S3.
  • IAM policies restrict EC2 instance access to only necessary services.

2.Application Tier (Logic Layer)

Components:

  • Private Subnets for isolation.
  • EC2 Instances to host backend services like Node.js, Java, or Python apps.
  • Internal Load Balancer for internal communication between web and app layers.
  • IAM roles attached to instances to securely access services like RDS or S3.

Features:

  • No direct internet access (inbound).
  • Communicates with web tier and database tier.
  • Logs can be shipped to CloudWatch or S3 for monitoring.

3.Database Tier (Data Layer)

Components:

  • Private Subnets in multiple AZs for fault tolerance.
  • Amazon Aurora (RDS) as the primary database.
  • Aurora Read Replica for read scalability.
  • Security Groups control access only from App Tier.

Features:

  • Highly available and fault-tolerant with automatic backups.
  • IAM Database Authentication can be enabled for secure access.
  • Data is encrypted at rest and in transit.

Step By Step Guide

#1.VPC Creation

Design and implement a Virtual Private Cloud (VPC) to establish a secure, scalable, and highly available network infrastructure for the project. The VPC will serve as the core environment, hosting all application components while enforcing isolation, robust security controls, and optimized connectivity between resources.

Click on Create VPC and select the options from the below screenshots:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 2
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 3

After selecting those options click on Create VPC

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 4

Now edit the names of the subnets as shown below:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 5

#2.Security Group Creation

Create Security groups for Web-tier, Web-External-ALB, App-tier, App-Internal-ALB and RDS-tier:

Web-External-ALB:

Select the options from below screenshot and click on create security group:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 6

Web-tier:

Select the options from below screenshot and click on create security group:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 7

App-tier:

Select the options from below screenshot and click on create security group:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 8

App-Internal-ALB:

Select the options from below screenshot and click on create security group:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 9

RDS-tier:

Select the options from below screenshot and click on create security group:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 10

#3.S3 Bucket and IAM Role Setup

Create an S3 bucket and upload the application code:

Clone the code to local and upload into the bucket:

1. Create a bucket:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 11

2. Upload the code into the bucket:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 12

Set up an IAM role with the necessary permissions and attach it to the EC2 instance:

Go to IAM and click on Create Role

Now select the options from the below screenshots:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 13

Now click on Next and select the permission policy:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 14

Now click on Next and give the name for the Role and click on create Role:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 15

#4.Database Configuration

Launch and configure an RDS instance to serve as the backend database.

Go to Aurora and RDS and create a subnet group first:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 16

After selecting above options click on Create

Now go to Databases and click on Create Database

Now select the below options:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 17
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 18
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 19
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 20
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 21

After selecting the above options click on create:

#5.Application Tier Setup

Deploy application-tier resources, including the configuration of an internal load balancer for traffic distribution within the tier.

Creation of Instance and setup for App Tier

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 22
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 23
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 24
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 25

After selecting those options click on launch instance

In this instance we will do the App Server Setup and DB Server Configuration. Execute the below commands;

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 26

Now install mysql:

sudo yum install mysql -y
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 27

Configure MySQL Database:
Connect to the database and perform basic configuration: Replace below info with your DB information

mysql -h <database endpoint> -u admin -p

and enter the password

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 28

Create a database:

CREATE DATABASE webappdb;
SHOW DATABASES;
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 29
USE webappdb;

You will see ‘Database changed’

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 30

Execute the below code as a single code to create a table with the name ‘books’

CREATE TABLE IF NOT EXISTS books(
  id INT NOT NULL AUTO_INCREMENT, 
  amount DECIMAL(10,2), 
  description VARCHAR(100), 
  PRIMARY KEY(id)
);
SHOW TABLES;

use above command to verify

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 31

Lets insert some info into the table:

INSERT INTO books (amount, description) VALUES ('400', 'physics');

To verify whether the entry is really created or not

SELECT * FROM books;
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 32

to come out of the database use:

exit
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 33

Update Application Configuration to with DB information:
Update the application-code/app-tier/DbConfig.js file with your database credentials.

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 34

Now update the DbConfig.js in the s3 bucket by uploading the DbConfig.js in the bucket:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 35

Install and Configure Node.js and PM2:

curl -o- https://raw.githubusercontent.com/avizway1/aws_3tier_architecture/main/install.sh | bash
source ~/.bashrc
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 36
nvm install 16
nvm use 16 
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 37

To run node as a service, we will install pm2:

npm install -g pm2
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 38

Now download application code from S3 and start the application:

cd ..
cd ..
cd ~/ 

Use the path of your code:

sudo aws s3 cp s3://<S3BucketName>/application.code/app-tier/ app-tier --recursive
cd app-tier
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 39
npm install
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 40

ls —-> You will see ‘index.js’ file. We have to start that.

pm2 start index.js
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 41

You will see the status as ‘online’

Now use

pm2 startup
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 42

To save the configuration use:

pm2 save
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 43

Verify that the application is running by executing

curl http://localhost:4000/health

It should return: This is the health check.

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 44

With this we have completed the application configuration.

Creation of Internal Load Balancer for App Tier

Go to EC2 > target groups and click on create target group

Select the below options:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 45
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 46

Then click on Next

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 47

Select the instance, click on include as pending below and then click on create target group

Now go to Load Balancers and click on create load balancer:

Select Application Load Balancer

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 48

Now select the following options:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 49
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 50
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 51

Now click on create load balancer

Goto the cloned code folder in local system —-> Open nginx.conf file and in the end of the file you will see something like below;
#proxy for internal lb
location /api/{
proxy_pass http://[REPLACE-WITH-INTERNAL-LB-DNS]:80/;
}

Replace the LB DNS in the above

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 52

Now upload the updated nginx.conf file to the S3 bucket:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 53

#6.Web Tier Setup

Deploy Web-tier resources, including the configuration of an external load balancer

Creation of Instance and setup for Web Tier

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 54
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 55
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 56
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 57

After selecting those options click on launch instance

In this instance we will do the Web Server and Nginx Setup. Execute the below commands;

sudo -su ec2-user
cd /home/ec2-user
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 58
curl -o- https://raw.githubusercontent.com/avizway1/aws_3tier_architecture/main/install.sh | bash
source ~/.bashrc
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 59
nvm install 16
nvm use 16
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 60

Use the path of your code:

aws s3 cp s3://<S3 Bucker Name>/application.code/web-tier/ web-tier --recursive
cd web-tier
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 61
npm install
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 62
npm run build
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 63

Install Nginx:

sudo amazon-linux-extras install nginx1 -y
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 64

Update Nginx configuration:

cd /etc/nginx
ls
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 65

Replace the nginx.conf file with the one we uploaded to the bucket

sudo rm nginx.conf
sudo aws s3 cp s3://<S3 Bucker Name>/application.code/nginx.conf .
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 66

Restart the nginx service:

sudo service nginx restart
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 67
chmod -R 755 /home/ec2-user
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 68
sudo chkconfig nginx on
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 69

Add this inbound rule to the web-tier-instances’ security group to check whether the app is running or not:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 70

Now paste the instances’ public ip in a browser to check the app

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 71

Creation of Internal Load Balancer for Web Tier

Go to EC2 > target groups and click on create target group

Select the below options:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 72
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 73

Then click on Next

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 74

Select the instance, click on include as pending below and then click on create target group

Now go to Load Balancers and click on create load balancer:

Select Application Load Balancer

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 48

Now select the following options:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 76
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 77
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 78

Now click on create load balancer

#7.Using Custom Domain Using Route 53

Click on Create Hosted Zones

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 79

Select below options and click on create:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 80
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 81

Now copy and paste the NS values in your custom domain

Here i’m using godaddy

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 82
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 81

Now click on create record

select the below options and click on create records:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 84

Now go to Certificate manager and click on request:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 85
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 86
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 87

After creating click on create records in Route 53:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 88
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 89

click on create records

After some minutes you’ll see the issued status

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 90

Now go to the web-external-load balancer and add the HTTPS rule in inbound rules:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 91

Now go to web-external-load balancer and go to Listeners and Rules, click on add listener and add the below options and click on add:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 92
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 93

Now use the custom domain to access the application:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 94

#8.Creating AutoScaling Group

Web-tier-ASG

Select the web-tier instance > actions > images and templates > create image:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 95

Select the below options and click on create AMI:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 96

Now go to Launch Template and click on create launch template and select below options:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 97
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 98
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 99
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 100

After selecting those options click on create launch template

Now go to Autoscaling group and click on Create Auto Scaling group and select below options:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 101
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 102
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 103
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 104

After creating Autoscaling group we can see a new instance got created as i gave the min desired capacity as 1:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 105

Now do the same for the App-tier-ASG

App-tier-ASG

Select the app-tier instance > actions > images and templates > create image:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 106

Select the below options and click on create AMI:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 107

Now go to Launch Template and click on create launch template and select below options:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 108
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 109
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 110
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 111

After selecting those options click on create launch template

Now go to Autoscaling group and click on Create Auto Scaling group and select below options:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 112
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 113
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 114
How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 115

After creating Autoscaling group we can see a new instance got created as i gave the min desired capacity as 1:

How to Set Up a 3-Tier Architecture on AWS with EC2, RDS, and S3 116

Security Considerations

  • IAM Roles and Policies: Used instead of hardcoding credentials in EC2 or applications.
  • Security Groups & NACLs: Used to restrict access across tiers.
  • ACM: Issues SSL certificates for secure communication.
  • S3 Bucket Policies: Enforce secure access to web content and logs.

Scalability and High Availability

  • EC2 Auto Scaling can be implemented in both Web and App tiers.
  • Aurora supports read replicas and multi-AZ deployments.
  • ELBs ensure fault-tolerant and balanced traffic distribution.

Conclusion:

By implementing a 3-tier architecture on AWS, you achieve a clean separation of concerns, scalability, and improved security. AWS provides all the necessary services—networking, compute, storage, DNS, certificates, and identity management—to build a production-ready application stack.

This architecture is ideal for web apps, SaaS platforms, and enterprise applications that require a modular, scalable, and secure setup.

Related Articles:

Multi Tier WebApp with Python Django and PostgreSQL

Reference:

Building a three-tier architecture on a budget

Harish Reddy

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Share via
Copy link
Powered by Social Snap