- Use Case
- Overview
- Architecture
- Prerequisites
- Project Structure
- Quick Start
- Configuration
- Deployment
- Monitoring & Logging
- Security
- Troubleshooting
- Cost Optimization
- Contributing
You are a Senior Cloud Infrastructure Engineer at CloudAutomation Solutions, a digital transformation consultancy that helps enterprises migrate their legacy applications to the cloud. Your team has been contracted by a major financial services company to modernize their customer-facing web application that currently runs on on-premises infrastructure.
- π’ Legacy Challenge: Replace aging on-premises infrastructure running a monolithic web application
- π Scale Expectations: Handle 10,000+ concurrent users during peak trading hours
- π Security Compliance: Meet strict financial regulations (PCI DSS, SOC 2 compliance)
- β° High Availability: 99.95% uptime SLA with < 2 seconds response time
- π Global Reach: Serve customers across multiple geographic regions
- π° Cost Control: Reduce infrastructure costs by 40% while improving performance
Deploy a production-ready two-tier architecture that provides:
- Web Tier: Auto-scaling application servers behind a load balancer
- Database Tier: Highly available Aurora MySQL cluster with read replicas
- Security Layer: WAF protection, encryption at rest/transit, and network isolation
- Global Distribution: CDN for improved performance and reduced latency
- Disaster Recovery: Multi-AZ deployment with automated backups
- Traffic Spikes: Handle sudden load increases during market volatility
- Database Performance: Optimize read-heavy workloads with read replicas
- Security: Implement defense-in-depth with multiple security layers
- Monitoring: Real-time observability for proactive issue resolution
- Cost Optimization: Auto-scaling to match demand and minimize waste
- β Performance: Sub-2 second page load times globally
- β Scalability: Automatic scaling from 2 to 20+ instances based on demand
- β Availability: Zero unplanned downtime during 6-month pilot period
- β Security: Pass all compliance audits and penetration tests
- β Cost Efficiency: 40% reduction in total infrastructure costs
This Terraform infrastructure provides the foundation to meet all these requirements through Infrastructure as Code, enabling repeatable, consistent deployments across multiple environments (dev/staging/production) while maintaining enterprise-grade security and performance standards.
This project implements a production-ready two-tier web application architecture on AWS using Infrastructure as Code (IaC) with Terraform. The architecture follows AWS Well-Architected Framework principles and implements industry best practices for security, scalability, and high availability.
- Scalability: Handle variable traffic loads with auto-scaling capabilities
- High Availability: 99.99% uptime with multi-AZ deployment
- Security: Zero-trust security model with WAF, encryption, and IAM
- Cost Optimization: Right-sized resources with automated scaling
- Maintainability: Modular, version-controlled infrastructure
- ποΈ Modular Terraform Architecture - Reusable, maintainable modules
- π Security-First Design - WAF, encryption at rest/transit, security groups
- π Auto Scaling & Load Balancing - Dynamic scaling based on metrics
- π Global Content Delivery - CloudFront CDN with edge locations
- π‘οΈ SSL/TLS Termination - AWS Certificate Manager integration
- π Monitoring & Alerting - CloudWatch metrics and alarms
- ποΈ Database High Availability - RDS Aurora with read replicas
- π DNS Management - Route 53 with health checks
Conceptual overview of the two-tier architecture design
| Tier | Component | Purpose | Availability |
|---|---|---|---|
| Web Tier | Application Load Balancer | Traffic distribution & SSL termination | Multi-AZ |
| Web Tier | Auto Scaling Group | Dynamic EC2 instance management | Multi-AZ |
| Web Tier | EC2 Instances | Application hosting | Multi-AZ |
| Database Tier | RDS Aurora MySQL | Primary database cluster | Multi-AZ |
| Database Tier | Aurora Read Replica | Read scaling & disaster recovery | Multi-AZ |
| Global | CloudFront CDN | Content delivery & caching | Global |
| Security | AWS WAF | Web application firewall | Regional |
| Tool | Version | Installation |
|---|---|---|
| Terraform | β₯ 1.0.0 | Install Guide |
| AWS CLI | β₯ 2.0.0 | Install Guide |
| Git | β₯ 2.30.0 | Install Guide |
| jq | Latest | brew install jq (macOS) |
- AWS Account with appropriate permissions
- Domain Name registered (for SSL certificate)
- IAM User/Role with following permissions:
AdministratorAccess(recommended for initial setup)- Or specific permissions for: EC2, VPC, RDS, Route53, CloudFront, WAF, IAM
This template is tested and supports deployment in:
us-east-1(N. Virginia)us-west-2(Oregon)eu-west-1(Ireland)ap-southeast-1(Singapore)
Two-Tier-Application/
βββ π main.tf # Root module & provider configuration
βββ π variables.tf # Input variables definition
βββ π variables.tfvars # Variable values (customize this)
βββ π backend.tf # Terraform state backend configuration
βββ π outputs.tf # Output values
βββ π README.md # This documentation
βββ π .gitignore # Git ignore rules
βββ π modules/ # Reusable Terraform modules
βββ π aws-vpc/ # VPC, subnets, IGW, NAT
β βββ main.tf
β βββ variables.tf
βββ π security-group/ # Security groups & rules
β βββ main.tf
β βββ variable.tf
β βββ gather.tf
βββ π aws-rds/ # RDS Aurora cluster
β βββ main.tf
β βββ variables.tf
β βββ gather.tf
βββ π alb-tg/ # Application Load Balancer
β βββ main.tf
β βββ variables.tf
β βββ gather.tf
βββ π aws-autoscaling/ # Auto Scaling Group & Launch Template
β βββ main.tf
β βββ variable.tf
β βββ gather.tf
β βββ deploy.sh
βββ π aws-iam/ # IAM roles, policies, instance profiles
β βββ iam-role.tf
β βββ iam-policy.tf
β βββ iam-instance-profile.tf
β βββ variables.tf
β βββ iam-role.json
β βββ iam-policy.json
βββ π aws-waf-cdn-acm-route53/ # WAF, CloudFront, ACM, Route53
βββ waf.tf
βββ cdn.tf
βββ acm.tf
βββ route53.tf
βββ variables.tf
βββ gather.tf
git clone https://github.com/Ike-DevCloudIQ/Two-Tier-Application.git
cd Two-Tier-Application# Method 1: AWS CLI
aws configure
# Method 2: Environment Variables
export AWS_ACCESS_KEY_ID="your-access-key"
export AWS_SECRET_ACCESS_KEY="your-secret-key"
export AWS_DEFAULT_REGION="eu-west-1"
# Method 3: AWS SSO (Recommended)
aws sso login --profile your-profilecp variables.tfvars variables.tfvars.local
# Edit variables.tfvars.local with your values# Initialize Terraform
terraform init
# Plan deployment
terraform plan -var-file="variables.tfvars"
# Apply configuration
terraform apply -var-file="variables.tfvars"The following screenshots demonstrate the successful deployment of all infrastructure components in AWS:
Terraform Plan Output: Complete infrastructure planning showing all resources to be created

Terraform plan output showing VPC infrastructure components to be provisioned
VPC Resource Map: Complete network topology with public/private subnets, internet gateway, and NAT gateways

AWS VPC Console showing the deployed Two-Tier-VPC with all networking components
NAT Gateways: Multi-AZ NAT gateway deployment for outbound internet access from private subnets

NAT Gateways deployed in each public subnet for high availability
Security Groups: Network-level security rules for web and database tiers

Security groups implementing defense-in-depth security model
Launch Templates: EC2 launch template configuration with user data and security settings

Launch template defining EC2 instance configuration for auto scaling
Auto Scaling Groups: Configured ASG with desired capacity, availability zones, and scaling policies

Auto Scaling Group managing EC2 instances across multiple availability zones
Application Load Balancer: Internet-facing ALB distributing traffic across multiple AZs with health checks

ALB configuration with target groups and health check settings
RDS Aurora Cluster: Managed Aurora MySQL cluster with primary instance and read replica

Aurora cluster with writer and reader instances for high availability
Route 53 Hosted Zone: DNS management for cloudautomation.site domain with health checks

Route 53 hosted zone configuration with DNS records and routing policies
β
VPC & Subnets β Securely isolated environment for your application
β
IAM & Role-Based Access Control β Fine-grained security permissions
β
AWS WAF β Protect against common web threats
β
Auto Scaling Group β Dynamic scaling based on demand
β
Application Load Balancer (ALB) β Efficient traffic distribution
β
EC2 Instances β Reliable computing power
β
Amazon RDS β Managed database for scalability and reliability
β
S3 Buckets β Secure storage for application assets
β
Amazon Route 53 β Scalable domain name system (DNS)
β
Amazon CloudFront (CDN) β Faster content delivery worldwide
β
SSL/TLS Encryption β Secure communication with ACM
