Aller au contenu principal

Architecture Web sur AWS

Introduction​

Déployer un service web sur AWS nécessite de combiner plusieurs services : VPC, EC2, Load Balancer, et une bonne stratégie de sécurité. Cette section couvre les patterns d'architecture les plus courants.

Pattern 1 : Architecture Simple​

Une Instance EC2 Publique​

┌─────────────────────────────────────────────────────────────┐
│ ARCHITECTURE SIMPLE (dev/test) │
├─────────────────────────────────────────────────────────────┤
│ │
│ INTERNET │
│ │ │
│ ▼ │
│ ┌──────────┐ │
│ │ IGW │ │
│ └────┬─────┘ │
│ │ │
│ ┌─────────────────────┼─────────────────────┐ │
│ │ VPC │ │ │
│ │ │ │ │
│ │ ┌─────────────────▼───────────────────┐ │ │
│ │ │ SUBNET PUBLIC │ │ │
│ │ │ │ │ │
│ │ │ ┌─────────────────┐ │ │ │
│ │ │ │ EC2 │ │ │ │
│ │ │ │ Web Server │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ │ IP: 52.1.2.3 │ │ │ │
│ │ │ │ SG: web-server │ │ │ │
│ │ │ └─────────────────┘ │ │ │
│ │ │ │ │ │
│ │ └──────────────────────────────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────┘ │
│ │
│ Avantages : │
│ ✅ Simple à déployer │
│ ✅ Coût minimal │
│ ✅ Idéal pour dev/test │
│ │
│ Inconvénients : │
│ ❌ Pas de haute disponibilité │
│ ❌ Un seul point de défaillance │
│ ❌ Pas scalable │
│ │
└─────────────────────────────────────────────────────────────┘

Configuration​

# 1. Créer un Security Group pour le web
aws ec2 create-security-group \
--group-name sg-web-simple \
--description "Web server SG" \
--vpc-id vpc-xxx

# 2. Autoriser HTTP et HTTPS
aws ec2 authorize-security-group-ingress \
--group-id sg-xxx \
--protocol tcp --port 80 --cidr 0.0.0.0/0

aws ec2 authorize-security-group-ingress \
--group-id sg-xxx \
--protocol tcp --port 443 --cidr 0.0.0.0/0

# 3. Lancer l'instance
aws ec2 run-instances \
--image-id ami-xxx \
--instance-type t3.micro \
--subnet-id subnet-public \
--security-group-ids sg-xxx \
--associate-public-ip-address \
--user-data '#!/bin/bash
yum install -y httpd
systemctl start httpd
echo "Hello World" > /var/www/html/index.html'

Pattern 2 : Architecture avec Load Balancer​

ALB + Instances Privées​

┌─────────────────────────────────────────────────────────────────────────┐
│ ARCHITECTURE AVEC ALB (production) │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ INTERNET │
│ │ │
│ ▼ │
│ ┌──────────┐ │
│ │ IGW │ │
│ └────┬─────┘ │
│ │ │
│ ┌────────────────────────────┼────────────────────────────────┐ │
│ │ VPC │ (10.0.0.0/16) │ │
│ │ │ │ │
│ │ ┌────────────────────────┴────────────────────────────┐ │ │
│ │ │ SUBNETS PUBLICS │ │ │
│ │ │ │ │ │
│ │ │ ┌─────────────┐ ┌─────────────┐ │ │ │
│ │ │ │ Public 1a │ │ Public 1b │ │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ │ ┌───────┐ │ │ ┌───────┐ │ │ │ │
│ │ │ │ │ ALB │◄─┼──────────────┼──│ ALB │ │ │ │ │
│ │ │ │ │ node │ │ │ │ node │ │ │ │ │
│ │ │ │ └───┬───┘ │ │ └───┬───┘ │ │ │ │
│ │ │ └──────┼──────┘ └──────┼──────┘ │ │ │
│ │ │ │ │ │ │ │
│ │ └─────────┼────────────────────────────┼───────────────┘ │ │
│ │ │ │ │ │
│ │ ┌─────────┼────────────────────────────┼───────────────┐ │ │
│ │ │ │ SUBNETS PRIVÉS │ │ │ │
│ │ │ │ │ │ │ │
│ │ │ ┌──────▼──────┐ ┌──────▼──────┐ │ │ │
│ │ │ │ Private 1a │ │ Private 1b │ │ │ │
│ │ │ │ │ │ │ │ │ │
│ │ │ │ ┌─────────┐ │ │ ┌─────────┐ │ │ │ │
│ │ │ │ │ EC2 │ │ │ │ EC2 │ │ │ │ │
│ │ │ │ │ Web 1 │ │ │ │ Web 2 │ │ │ │ │
│ │ │ │ └─────────┘ │ │ └─────────┘ │ │ │ │
│ │ │ └─────────────┘ └─────────────┘ │ │ │
│ │ │ │ │ │
│ │ └──────────────────────────────────────────────────────┘ │ │
│ │ │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │
│ Avantages : │
│ ✅ Haute disponibilité (Multi-AZ) │
│ ✅ Scalable (ajouter des instances) │
│ ✅ SSL termination au niveau ALB │
│ ✅ Serveurs web protégés (subnet privé) │
│ │
└─────────────────────────────────────────────────────────────────────────┘

Types de Load Balancers AWS​

TypeUsageLayer OSIProtocoles
ALBApplications HTTP/HTTPSLayer 7HTTP, HTTPS, gRPC
NLBPerformance ultraLayer 4TCP, UDP, TLS
CLBLegacyLayer 4/7TCP, SSL, HTTP, HTTPS
GWLBAppliances réseauLayer 3IP

Configuration ALB​

# 1. Créer le Target Group
aws elbv2 create-target-group \
--name tg-web-servers \
--protocol HTTP \
--port 80 \
--vpc-id vpc-xxx \
--health-check-path /health \
--health-check-interval-seconds 30

# 2. Créer l'Application Load Balancer
aws elbv2 create-load-balancer \
--name alb-web \
--subnets subnet-public-1a subnet-public-1b \
--security-groups sg-alb \
--scheme internet-facing \
--type application

# 3. Créer le Listener
aws elbv2 create-listener \
--load-balancer-arn arn:aws:elasticloadbalancing:...:alb-web \
--protocol HTTP \
--port 80 \
--default-actions Type=forward,TargetGroupArn=arn:aws:...:tg-web-servers

# 4. Enregistrer les instances
aws elbv2 register-targets \
--target-group-arn arn:aws:...:tg-web-servers \
--targets Id=i-web1 Id=i-web2

Pattern 3 : Architecture 3-Tiers​

Web + App + Database​

┌─────────────────────────────────────────────────────────────────────────┐
│ ARCHITECTURE 3-TIERS │
├─────────────────────────────────────────────────────────────────────────┤
│ │
│ INTERNET │
│ │ │
│ ┌──────▼──────┐ │
│ │ IGW │ │
│ └──────┬──────┘ │
│ │ │
│ ┌──────────────────────────────┼──────────────────────────────┐ │
│ │ VPC │ │ │
│ │ │ │ │
│ │ ╔══════════════════════════╧════════════════════════════╗ │ │
│ │ ║ TIER 1 : PRÉSENTATION ║ │ │
│ │ ║ (Subnet Public) ║ │ │
│ │ ║ ║ │ │
│ │ ║ ┌─────────────────────────┐ ║ │ │
│ │ ║ │ Application Load │ ║ │ │
│ │ ║ │ Balancer (ALB) │ ║ │ │
│ │ ║ └───────────┬─────────────┘ ║ │ │
│ │ ╚═══════════════════════╪═══════════════════════════════╝ │ │
│ │ │ │ │
│ │ ╔═══════════════════════╪═══════════════════════════════╗ │ │
│ │ ║ TIER 2 : APPLICATION ║ │ │
│ │ ║ (Subnet Privé App) ║ │ │
│ │ ║ │ ║ │ │
│ │ ║ ┌────────────────────┼────────────────────┐ ║ │ │
│ │ ║ │ │ │ ║ │ │
│ │ ║ ┌───▼───┐ ┌─────▼─────┐ ┌─────▼───┐ ║ │ │
│ │ ║ │ EC2 │ │ EC2 │ │ EC2 │ ║ │ │
│ │ ║ │ App 1 │ │ App 2 │ │ App 3 │ ║ │ │
│ │ ║ └───┬───┘ └─────┬─────┘ └────┬────┘ ║ │ │
│ │ ║ │ │ │ ║ │ │
│ │ ╚══════╪════════════════════╪═══════════════════╪═══════╝ │ │
│ │ │ │ │ │ │
│ │ ╔══════╪════════════════════╪═══════════════════╪═══════╗ │ │
│ │ ║ │ TIER 3 : DONNÉES │ │ ║ │ │
│ │ ║ │ (Subnet Privé DB) │ ║ │ │
│ │ ║ │ │ │ ║ │ │
│ │ ║ └────────────────────┼───────────────────┘ ║ │ │
│ │ ║ │ ║ │ │
│ │ ║ ┌──────▼──────┐ ║ │ │
│ │ ║ │ RDS │ ║ │ │
│ │ ║ │ MySQL │ ║ │ │
│ │ ║ │ Multi-AZ │ ║ │ │
│ │ ║ └─────────────┘ ║ │ │
│ │ ║ ║ │ │
│ │ ╚════════════════════════════════════════════════════════╝ │ │
│ │ │ │
│ └───────────────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────────────────┘

Security Groups pour 3-Tiers​

┌─────────────────────────────────────────────────────────────┐
│ SECURITY GROUPS 3-TIERS │
├─────────────────────────────────────────────────────────────┤
│ │
│ sg-alb (Load Balancer) │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Inbound: HTTP/443 from 0.0.0.0/0 │ │
│ │ Outbound: HTTP/80 to sg-app │ │
│ └─────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ sg-app (Application Servers) │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Inbound: HTTP/80 from sg-alb │ │
│ │ Inbound: SSH/22 from sg-bastion │ │
│ │ Outbound: MySQL/3306 to sg-db │ │
│ │ Outbound: HTTPS/443 to 0.0.0.0/0 (APIs externes) │ │
│ └─────────────────────────────────────────────────────┘ │
│ │ │
│ ▼ │
│ sg-db (Database) │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Inbound: MySQL/3306 from sg-app │ │
│ │ Outbound: Aucun (ou minimal) │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ Principe : Chaque tier n'accepte QUE le trafic du tier │
│ précédent │
│ │
└─────────────────────────────────────────────────────────────┘

Health Checks​

Configuration Health Check ALB​

┌─────────────────────────────────────────────────────────────┐
│ HEALTH CHECKS ALB │
├─────────────────────────────────────────────────────────────┤
│ │
│ Paramètres importants : │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Protocol : HTTP │ │
│ │ Path : /health ou /api/health │ │
│ │ Port : traffic-port (80) │ │
│ │ Healthy threshold : 2 (succès consécutifs) │ │
│ │ Unhealthy threshold : 3 (échecs consécutifs) │ │
│ │ Timeout : 5 seconds │ │
│ │ Interval : 30 seconds │ │
│ │ Success codes : 200-299 │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ Endpoint /health typique : │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ HTTP 200 OK │ │
│ │ { │ │
│ │ "status": "healthy", │ │
│ │ "database": "connected", │ │
│ │ "cache": "connected" │ │
│ │ } │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘

DNS avec Route 53​

┌─────────────────────────────────────────────────────────────┐
│ ROUTE 53 + ALB │
├─────────────────────────────────────────────────────────────┤
│ │
│ Utilisateur tape : www.monsite.com │
│ │ │
│ ▼ │
│ ┌──────────────┐ │
│ │ Route 53 │ │
│ │ DNS │ │
│ └──────┬───────┘ │
│ │ │
│ │ Alias Record │
│ │ www.monsite.com │
│ │ → alb-web-xxx.elb.amazonaws.com│
│ │ │
│ ▼ │
│ ┌──────────────┐ │
│ │ ALB │ │
│ └──────────────┘ │
│ │
│ Types d'enregistrements : │
│ • A (Alias) : Pointe vers ressource AWS (ALB, CF, S3) │
│ • CNAME : Pointe vers un autre nom de domaine │
│ │
│ Avantage Alias : │
│ ✅ Gratuit pour requêtes vers ressources AWS │
│ ✅ Répond avec les IPs directement │
│ │
└─────────────────────────────────────────────────────────────┘

Résumé des Patterns​

PatternComplexitéCoûtHACas d'usage
EC2 Simple⭐$❌Dev/Test
ALB + EC2⭐⭐$$✅Production simple
3-Tiers⭐⭐⭐$$$✅✅Production
Microservices⭐⭐⭐⭐$$$$✅✅✅Large scale

Prochaine section : Lab : Publication Web