πŸ’‘ Ask Tutor

Real-World Project – Hosting a Scalable Web App on AWS

From Architecture to Deployment of a Full-Stack, Scalable, and Secure Web Application

This chapter ties together everything we’ve learnedβ€”compute, networking, databases, IAM, and monitoringβ€”into a real-world project: deploying a scalable, fault-tolerant web application using AWS services.

Project Overview

You’ll build and deploy a two-tier web application with the following characteristics:

LayerTechnology
FrontendHTML/CSS/JavaScript (static website)
Backend/APINode.js or Python (running on EC2 or Lambda)
DatabaseAmazon RDS (MySQL) or DynamoDB
StorageAmazon S3 for static assets
Load BalancingApplication Load Balancer (ALB)
Auto ScalingEC2 Auto Scaling Group or Lambda scaling
MonitoringCloudWatch, CloudTrail, GuardDuty
SecurityIAM, SGs, VPC, HTTPS via ACM

Architecture Diagram

LESS
            [ User Browser ]
                   |
               [ Route 53 ]
                   |
         [ Application Load Balancer ]
                 /       \
        [ EC2 Instance A ] [ EC2 Instance B ] ← Auto Scaling Group
                 \       /
           [ Amazon RDS - MySQL ]
                   |
          [ Amazon CloudWatch Logs ]
                   |
          [ AWS IAM + VPC Security ]

πŸ” All communication secured with HTTPS + IAM roles for instance-to-service access.

Step-by-Step: Infrastructure Setup

Step 1: VPC and Subnets

  • Create custom VPC (10.0.0.0/16)
  • Create 2 Public Subnets (e.g., 10.0.1.0/24, 10.0.2.0/24)
  • Create 2 Private Subnets for RDS
  • Attach an Internet Gateway
  • Add Route Tables:
    • Public β†’ IGW
    • Private β†’ NAT Gateway

Step 2: EC2 Launch Configuration

  • Create a Launch Template with:
    • Amazon Linux 2 / Ubuntu
    • User Data Script (installs Node.js/Python app)
    • IAM Role: access to CloudWatch, S3
    • Security Group: allow port 80/443 from ALB only
Bash
#!/bin/bash
yum update -y
yum install -y nodejs npm git
git clone https://github.com/myuser/myapp.git
cd myapp
npm install
npm start

πŸ’‘ Use Elastic Beanstalk or Docker + ECS for containerized deployments.

Step 3: Application Load Balancer

  • Target Type: EC2
  • Protocol: HTTP or HTTPS (with ACM certificate)
  • Health Check Path: /health
  • Listener Rules: Route traffic to target group
  • Attach to Auto Scaling Group

Step 4: Auto Scaling Group

  • Attach to public subnets
  • Min instances: 2, Max: 10
  • Scaling policy: CPU > 70% β†’ add instance
  • Use CloudWatch Alarm to trigger scaling

Step 5: RDS Configuration

  • Engine: MySQL or PostgreSQL
  • Multi-AZ: Enabled
  • Instance Type: db.t3.medium
  • Subnet Group: Private subnets only
  • Storage: 20 GB, enable auto-scaling
  • Enable automatic backups
  • Connect from EC2 via security group reference, not public IP

Step 6: Store Static Assets on S3

  • Create bucket: myapp-static-content
  • Enable static website hosting
  • Upload HTML, CSS, JS
  • Optional: Distribute via CloudFront

πŸ›‘οΈ Block public access via bucket policy and use signed URLs if needed.

Step 7: Domain Setup with Route 53

  • Buy/transfer domain to Route 53
  • Create Hosted Zone
  • Create A Record β†’ ALB DNS name
  • Enable HTTPS via ACM Certificate and attach to ALB

Step 8: Monitoring and Logging

ComponentMonitoring Tool
EC2 + Auto ScalingCloudWatch Metrics, Alarms
ALB Access LogsS3 or CloudWatch Logs
App LogsCloudWatch Agent
RDS PerformanceEnhanced Monitoring
Security EventsAWS GuardDuty, CloudTrail

Step 9: Security Configuration

LayerBest Practice
VPCPublic subnets for ALB, private for DB
EC2No public IPs, use NAT
IAMRoles for EC2, RDS auth, S3 read
Data EncryptionKMS + TLS everywhere
SGsLeast-privilege, app SG talks only to DB SG

Step 10: Cost Optimization Tips

  • Use t3.micro for dev (Free Tier eligible)
  • Enable EC2 Auto Scaling to reduce idle compute
  • Schedule non-prod EC2s to stop at night
  • Use Aurora Serverless or DynamoDB on-demand
  • Set up budgets in Billing Dashboard

πŸ“¦ Deployment Automation (Optional)

Use CloudFormation or CDK to define your entire stack:

Bash
cdk deploy

Or use CodePipeline + CodeBuild to:

  • Detect changes in GitHub
  • Run build scripts
  • Deploy automatically to EC2 or S3

βœ… Final Checklist

TaskStatus
Custom VPC with subnetsβœ…
EC2 instances with IAM rolesβœ…
Auto Scaling and ALBβœ…
Secure RDS setupβœ…
S3 + CloudFront (optional)βœ…
HTTPS with ACMβœ…
Monitoring and alarmsβœ…
Domain routing via Route 53βœ…
Logs centralized to CloudWatchβœ