AWS Three-Tier Web Architecture: Comprehensive Setup Guide

Architecture Overview

Image description)

The three-tier web architecture is a proven design pattern that separates an application into three logical tiers:

  1. Presentation Tier (Web Tier)
  2. Application Tier (App Tier)
  3. Data Tier (Database Tier)

Key Components

  • Virtual Private Cloud (VPC)
  • Subnets across multiple Availability Zones
  • Internet Gateway
  • NAT Gateway
  • Security Groups
  • Elastic Load Balancers
  • EC2 Instances
  • RDS Database
  • S3 Bucket

1. Network Infrastructure Setup

1.1 VPC Configuration

Image description

  • Create a VPC with CIDR block (e.g., 10.0.0.0/16)
  • Enable DNS hostnames and support
  • Use VPC Wizard or AWS Console "VPC and more" feature

Subnet Strategy

  • Public Subnets (Web Tier):

    • For internet-facing resources
    • Typically in different Availability Zones
    • Associated with Internet Gateway
  • Private Subnets (App and Database Tiers):

    • For internal application and database resources
    • Not directly accessible from the internet
    • Routed through NAT Gateway

1.2 Internet and NAT Gateways

Image description

  • Create an Internet Gateway and attach to VPC
  • Create NAT Gateway in each public subnet
  • Configure route tables to direct traffic appropriately

1.3 Security Groups

Image description

Create distinct security groups for:

  • Web Tier EC2 Instances
  • Application Tier EC2 Instances
  • Load Balancers
  • RDS Database

Best Practices

  • Implement least privilege principle
  • Only open necessary ports
  • Restrict inbound and outbound traffic

Sample Web Security Group

Image description

1.4 Route Table

Image description

2. Compute Resources

2.1 EC2 Instances and Roles

Image description

Image description

  • Launch instances in private subnets
  • Use Amazon Linux 2 or Amazon Linux 2023
  • Create IAM roles for SSM and S3 access

Web Tier EC2

  • Hosts web server and frontend
  • Placed in public subnet behind load balancer

Application Tier EC2

  • Hosts backend application logic
  • Placed in private subnet
  • Communicates with database tier

3. Database Tier

3.1 RDS Configuration

Image description

Image description

  • Use Amazon Aurora MySQL
  • Multi-AZ deployment for high availability
  • Create subnet group across multiple AZs

Database Setup Steps

  1. Create subnet group
  2. Choose Dev/Test template
  3. Configure database insights
  4. Set up monitoring (optional)

3.2 Database Configuration

-- Create database
CREATE DATABASE webappdb;

-- Create transactions table
CREATE TABLE transactions (
    id INT NOT NULL AUTO_INCREMENT,
    amount DECIMAL(10,2),
    description VARCHAR(100),
    PRIMARY KEY(id)
);

-- Insert sample data
INSERT INTO transactions (amount, description) 
VALUES 
    (400, 'groceries'),
    (100, 'class'),
    (200, 'other groceries'),
    (10, 'brownies');

4. Storage and Code Deployment

4.1 S3 Bucket

Image description

Image description

  • Create S3 bucket for application code
  • Use versioning and encryption
  • Configure appropriate IAM policies

4.2 Code Deployment

# Clone repository
git clone https://github.com/Naveen3251/AWS_3Tier.git

# Update database configuration
# Edit app-tier/DbConfig.js with:
# - RDS endpoint
# - Database credentials
# - Database name (webappdb)

5. Application Setup

EC2 SSM Installation

5.1 Node.js Configuration

# Install Node Version Manager (NVM)
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

# Install Node.js
nvm install 16
nvm use 16

# Install PM2 process manager
npm install -g pm2

# Install application dependencies
npm install

# Start application
pm2 start index.js
pm2 startup
pm2 save

5.2 Verification Endpoints

  • Health Check: GET /health
  • Transactions: GET /transaction

6. Internal Load Balancing and Auto Scaling

Create Target Group:

Image description

Image description

Create Load Balancer:

Image description

Review

Image description

Image description

Launch Template:

Image description

Load Balancer:
Image description

Image description

Image description

Image description

Image description

Update Config File
Web Instance Deployment
Configure Web Instance

7. Monitoring and Maintenance

  • Enable AWS CloudWatch metrics
  • Set up alarms for resource utilization
  • Regularly update and patch instances
  • Implement backup strategies

Estimated Costs

  • Monitor resources using AWS Cost Explorer
  • Consider using AWS Budgets
  • Leverage AWS Free Tier for learning