Cloud Architect
You are an expert at designing cloud infrastructure and architecture.
This skill activates when the user needs help with:
Ask about:
Three-Tier Web Application:
┌─────────────────────────────────────────────────────────────────┐
│ THREE-TIER ARCHITECTURE │
├─────────────────────────────────────────────────────────────────┤
│ │
│ ┌──────────────────────────────────────────────────────────┐ │
│ │ PRESENTATION TIER │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ CDN │───▶│ ALB │───▶│ WAF │ │ │
│ │ │CloudFront│ │ │ │ │ │ │
│ │ └─────────┘ └────┬────┘ └─────────┘ │ │
│ └──────────────────────┼───────────────────────────────────┘ │
│ │ │
│ ┌──────────────────────┼───────────────────────────────────┐ │
│ │ APPLICATION TIER │ │
│ │ ┌────────────┼────────────┐ │ │
│ │ ▼ ▼ ▼ │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ EC2 │ │ EC2 │ │ EC2 │ (Auto Scaling)│ │
│ │ │ or ECS │ │ or ECS │ │ or ECS │ │ │
│ │ └────┬────┘ └────┬────┘ └────┬────┘ │ │
│ └─────────┼────────────┼────────────┼──────────────────────┘ │
│ │ │ │ │
│ ┌─────────┼────────────┼────────────┼──────────────────────┐ │
│ │ DATA TIER │ │
│ │ ┌────▼────┐ ┌────▼────┐ ┌────▼────┐ │ │
│ │ │ RDS │ │ ElastiC │ │ S3 │ │ │
│ │ │(Primary)│ │ ache │ │ │ │ │
│ │ └────┬────┘ └─────────┘ └─────────┘ │ │
│ │ │ │ │
│ │ ┌────▼────┐ │ │
│ │ │ RDS │ │ │
│ │ │(Replica)│ │ │
│ │ └─────────┘ │ │
│ └──────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────┘
# main.tf - Core infrastructure
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
backend "s3" {
bucket = "terraform-state-bucket"
key = "prod/terraform.tfstate"
region = "us-east-1"
}
}
provider "aws" {
region = var.region
}
# VPC
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "5.0.0"
name = "${var.project}-vpc"
cidr = "10.0.0.0/16"
azs = ["${var.region}a", "${var.region}b", "${var.region}c"]
private_subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"]
public_subnets = ["10.0.101.0/24", "10.0.102.0/24", "10.0.103.0/24"]
enable_nat_gateway = true
single_nat_gateway = var.environment != "production"
tags = var.common_tags
}
# Application Load Balancer
resource "aws_lb" "main" {
name = "${var.project}-alb"
internal = false
load_balancer_type = "application"
security_groups = [aws_security_group.alb.id]
subnets = module.vpc.public_subnets
enable_deletion_protection = var.environment == "production"
}
resource "aws_lb_target_group" "app" {
name = "${var.project}-tg"
port = 8000
protocol = "HTTP"
vpc_id = module.vpc.vpc_id
target_type = "ip"
health_check {
path = "/health"
healthy_threshold = 2
unhealthy_threshold = 10
timeout = 30
interval = 60
}
}
# ECS Cluster
resource "aws_ecs_cluster" "main" {
name = "${var.project}-cluster"
setting {
name = "containerInsights"
value = "enabled"
}
}
# ECS Service
resource "aws_ecs_service" "app" {
name = "${var.project}-service"
cluster = aws_ecs_cluster.main.id
task_definition = aws_ecs_task_definition.app.arn
desired_count = var.app_count
launch_type = "FARGATE"
network_configuration {
security_groups = [aws_security_group.ecs.id]
subnets = module.vpc.private_subnets
}
load_balancer {
target_group_arn = aws_lb_target_group.app.arn
container_name = "app"
container_port = 8000
}
}
# RDS Database
resource "aws_db_instance" "main" {
identifier = "${var.project}-db"
engine = "postgres"
engine_version = "15"
instance_class = var.db_instance_class
allocated_storage = 20
storage_encrypted = true
db_name = var.db_name
username = var.db_username
password = var.db_password
vpc_security_group_ids = [aws_security_group.rds.id]
db_subnet_group_name = aws_db_subnet_group.main.name
backup_retention_period = 7
multi_az = var.environment == "production"
skip_final_snapshot = var.environment != "production"
}
# ElastiCache Redis
resource "aws_elasticache_cluster" "main" {
cluster_id = "${var.project}-redis"
engine = "redis"
node_type = "cache.t3.micro"
num_cache_nodes = 1
port = 6379
security_group_ids = [aws_security_group.redis.id]
subnet_group_name = aws_elasticache_subnet_group.main.name
}
# serverless.yml