Lab : Configuration Auto Scaling
Objectif du Lab
Concevoir et configurer une solution Auto Scaling complète pour une application web avec des patterns de trafic variables.
Partie 1 : Scénario
Contexte
NewsPortal est un site d'actualités qui connaît des pics de trafic imprévisibles lors de breaking news. L'équipe technique veut automatiser le scaling pour :
- Maintenir les performances pendant les pics
- Réduire les coûts pendant les heures creuses
Données de Trafic
┌─────────────────────────────────────────────────────────────┐
│ PATTERNS DE TRAFIC NEWSPORTAL │
├─────────────────────────────────────────────────────────────┤
│ │
│ JOURNÉE NORMALE │
│ ─────────────── │
│ │
│ Visiteurs ▲ │
│ │ ┌────┐ │
│ 50,000 ─┤ ┌┘ └┐ │
│ │ ┌┘ └┐ ┌──┐ │
│ 30,000 ─┤ ┌──┘ └──────┘ └┐ │
│ │ ┌──┘ └──┐ │
│ 10,000 ─┤──┘ └── │
│ │ │
│ └─────┬─────┬─────┬─────┬─────┬─────► Heure │
│ 6h 9h 12h 18h 21h │
│ │
│ BREAKING NEWS (imprévisible) │
│ ─────────────────────────── │
│ │
│ Visiteurs ▲ │
│ │ ▲ Pic soudain x10 │
│ 200,000 ─┤ ╱╲ │
│ │ ╱ ╲ │
│ 100,000 ─┤ ╱ ╲ │
│ │ ╱ ╲ │
│ 20,000 ─┤──────╱ ╲────────── │
│ │ │
│ └─────────────────────────────────► Temps │
│ │
└─────────────────────────────────────────────────────────────┘
Exigences
| Aspect | Exigence |
|---|---|
| Disponibilité | 99.9% |
| Temps de réponse | < 500ms (P95) |
| Capacité min | 5,000 visiteurs/min |
| Capacité max | 200,000 visiteurs/min |
| Budget | Optimiser les coûts hors pics |
Partie 2 : Exercices de Conception
Exercice 2.1 : Dimensionnement
Sachant qu'une instance t3.medium peut gérer 500 requêtes/seconde, calculez :
| Question | Votre Réponse |
|---|---|
| Instances minimum (normal) | ? |
| Instances pour pic x10 | ? |
| Min recommandé pour HA | ? |
| Max recommandé | ? |
💡 Solution
Trafic normal : 50,000 visiteurs/min = 833 req/sec
Instances nécessaires : 833 / 500 = 2 instances
Trafic pic x10 : 200,000 visiteurs/min = 3,333 req/sec
Instances nécessaires : 3,333 / 500 = 7 instances (arrondi)
Min recommandé : 2 (HA Multi-AZ)
Max recommandé : 10 (marge de sécurité)
Desired initial : 2
Exercice 2.2 : Choix de la Politique
Quelle(s) politique(s) de scaling recommandez-vous et pourquoi ?
| Politique | Appropriée ? | Justification |
|---|---|---|
| Target Tracking CPU | ? | ? |
| Target Tracking Requests | ? | ? |
| Scheduled | ? | ? |
| Step Scaling | ? | ? |
💡 Solution
| Politique | Appropriée ? | Justification |
|---|---|---|
| Target Tracking CPU | ⚠️ Partiel | Utile mais CPU pas toujours corrélé aux requêtes |
| Target Tracking Requests | ✅ OUI | Directement lié au trafic utilisateur |
| Scheduled | ⚠️ Partiel | Patterns jour/nuit prévisibles, mais pas les breaking news |
| Step Scaling | ✅ OUI | Réponse rapide aux pics soudains |
Recommandation : Combiner Target Tracking (requests) + Scheduled (base)
Exercice 2.3 : Configuration Launch Template
Complétez la configuration du Launch Template :
# Launch Template Configuration
LaunchTemplateName: newsportal-lt
# À compléter :
AMI: _______________
InstanceType: _______________
SecurityGroupIds:
- _______________
KeyName: _______________
UserData: |
#!/bin/bash
_______________
_______________
_______________
💡 Solution
LaunchTemplateName: newsportal-lt
AMI: ami-0123456789 (Amazon Linux 2, préconfiguré)
InstanceType: t3.medium
SecurityGroupIds:
- sg-web-servers
KeyName: newsportal-key
UserData: |
#!/bin/bash
yum update -y
yum install -y httpd
systemctl start httpd
systemctl enable httpd
# Ou déploiement de l'app via CodeDeploy
aws s3 cp s3://newsportal-deploy/latest.tar.gz /tmp/
tar -xzf /tmp/latest.tar.gz -C /var/www/html/
Exercice 2.4 : Configuration ASG
Complétez la configuration de l'Auto Scaling Group :
AutoScalingGroupName: newsportal-asg
# Capacité
MinSize: ___
MaxSize: ___
DesiredCapacity: ___
# Réseau (2 AZ minimum)
VPCZoneIdentifier:
- _______________
- _______________
# Health Checks
HealthCheckType: _______________
HealthCheckGracePeriod: ___
# Target Group
TargetGroupARNs:
- _______________
💡 Solution
AutoScalingGroupName: newsportal-asg
MinSize: 2
MaxSize: 10
DesiredCapacity: 2
VPCZoneIdentifier:
- subnet-private-az-a
- subnet-private-az-b
HealthCheckType: ELB # Utilise les health checks de l'ALB
HealthCheckGracePeriod: 300 # 5 minutes pour démarrage app
TargetGroupARNs:
- arn:aws:elasticloadbalancing:...:targetgroup/newsportal-tg/xxx
Partie 3 : Configuration des Politiques
Exercice 3.1 : Target Tracking
Créez une politique Target Tracking pour maintenir 1000 requêtes par cible :
# Complétez la commande
aws autoscaling put-scaling-policy \
--auto-scaling-group-name newsportal-asg \
--policy-name _______________ \
--policy-type _______________ \
--target-tracking-configuration '{
"TargetValue": ___,
"PredefinedMetricSpecification": {
"PredefinedMetricType": "_______________",
"ResourceLabel": "app/newsportal-alb/xxx/targetgroup/newsportal-tg/yyy"
},
"ScaleOutCooldown": ___,
"ScaleInCooldown": ___
}'
💡 Solution
aws autoscaling put-scaling-policy \
--auto-scaling-group-name newsportal-asg \
--policy-name request-target-tracking \
--policy-type TargetTrackingScaling \
--target-tracking-configuration '{
"TargetValue": 1000.0,
"PredefinedMetricSpecification": {
"PredefinedMetricType": "ALBRequestCountPerTarget",
"ResourceLabel": "app/newsportal-alb/xxx/targetgroup/newsportal-tg/yyy"
},
"ScaleOutCooldown": 60,
"ScaleInCooldown": 300
}'
Exercice 3.2 : Scheduled Scaling
Configurez le scaling schedulé pour les patterns jour/nuit :
# Morning scale up (8h UTC, Lun-Ven)
aws autoscaling put-scheduled-update-group-action \
--auto-scaling-group-name newsportal-asg \
--scheduled-action-name _______________ \
--recurrence "_______________ " \
--min-size ___ \
--max-size ___
# Evening scale down (22h UTC, tous les jours)
aws autoscaling put-scheduled-update-group-action \
--auto-scaling-group-name newsportal-asg \
--scheduled-action-name _______________ \
--recurrence "_______________" \
--min-size ___ \
--max-size ___
💡 Solution
# Morning scale up (8h UTC, Lun-Ven)
aws autoscaling put-scheduled-update-group-action \
--auto-scaling-group-name newsportal-asg \
--scheduled-action-name morning-scale-up \
--recurrence "0 8 * * MON-FRI" \
--min-size 3 \
--max-size 10
# Evening scale down (22h UTC, tous les jours)
aws autoscaling put-scheduled-update-group-action \
--auto-scaling-group-name newsportal-asg \
--scheduled-action-name evening-scale-down \
--recurrence "0 22 * * *" \
--min-size 2 \
--max-size 5
Partie 4 : Monitoring et Alertes
Exercice 4.1 : CloudWatch Dashboard
Listez les métriques essentielles à monitorer :
| Métrique | Namespace | Seuil Alerte |
|---|---|---|
| ? | AWS/EC2 | ? |
| ? | AWS/ApplicationELB | ? |
| ? | AWS/AutoScaling | ? |
| ? | Custom | ? |
💡 Solution
| Métrique | Namespace | Seuil Alerte |
|---|---|---|
| CPUUtilization | AWS/EC2 | > 80% |
| TargetResponseTime | AWS/ApplicationELB | > 500ms |
| RequestCount | AWS/ApplicationELB | info only |
| HealthyHostCount | AWS/ApplicationELB | < 2 |
| GroupDesiredCapacity | AWS/AutoScaling | info only |
| GroupInServiceInstances | AWS/AutoScaling | < min |
| HTTPCode_Target_5XX_Count | AWS/ApplicationELB | > 10/min |
Exercice 4.2 : Alerte de Scaling
Créez une alerte SNS pour notifier lors des événements de scaling :
# 1. Créer le topic SNS
aws sns create-topic --name _______________
# 2. S'abonner par email
aws sns subscribe \
--topic-arn arn:aws:sns:...:_______________ \
--protocol email \
--notification-endpoint _______________
# 3. Configurer les notifications ASG
aws autoscaling put-notification-configuration \
--auto-scaling-group-name newsportal-asg \
--topic-arn arn:aws:sns:...:_______________ \
--notification-types \
"autoscaling:EC2_INSTANCE_LAUNCH" \
"autoscaling:EC2_INSTANCE_TERMINATE" \
"_______________"
💡 Solution
# 1. Créer le topic SNS
aws sns create-topic --name newsportal-scaling-alerts
# 2. S'abonner par email
aws sns subscribe \
--topic-arn arn:aws:sns:us-east-1:123456789:newsportal-scaling-alerts \
--protocol email \
--notification-endpoint ops@newsportal.com
# 3. Configurer les notifications ASG
aws autoscaling put-notification-configuration \
--auto-scaling-group-name newsportal-asg \
--topic-arn arn:aws:sns:us-east-1:123456789:newsportal-scaling-alerts \
--notification-types \
"autoscaling:EC2_INSTANCE_LAUNCH" \
"autoscaling:EC2_INSTANCE_TERMINATE" \
"autoscaling:EC2_INSTANCE_LAUNCH_ERROR"
Partie 5 : Tests de Validation
Plan de Test
| Test | Méthode | Résultat Attendu |
|---|---|---|
| Scale Out | Générer charge | Nouvelles instances en < 5 min |
| Scale In | Arrêter charge | Réduction après cooldown |
| Failover | Terminer instance | Remplacement auto |
| Health Check | Stopper app | Instance marquée unhealthy |
Script de Test de Charge
#!/bin/bash
# test-load.sh - Simuler un pic de trafic
ALB_DNS="newsportal-alb-xxx.region.elb.amazonaws.com"
DURATION=300 # 5 minutes
CONCURRENCY=100
echo "Démarrage test de charge..."
echo "URL: http://$ALB_DNS"
echo "Durée: $DURATION secondes"
echo "Concurrence: $CONCURRENCY"
# Utiliser Apache Bench ou hey
hey -z ${DURATION}s -c $CONCURRENCY http://$ALB_DNS/
echo "Test terminé. Vérifiez CloudWatch et ASG."
Checklist de Validation
┌─────────────────────────────────────────────────────────────┐
│ CHECKLIST VALIDATION │
├─────────────────────────────────────────────────────────────┤
│ │
│ ☐ Scale out fonctionne (nouvelles instances) │
│ ☐ Scale in fonctionne (instances terminées) │
│ ☐ Health checks ALB détectent les pannes │
│ ☐ Instances unhealthy remplacées automatiquement │
│ ☐ Notifications SNS reçues │
│ ☐ Métriques visibles dans CloudWatch │
│ ☐ Scheduled actions respectées │
│ ☐ Temps de réponse maintenu < 500ms sous charge │
│ │
└─────────────────────────────────────────────────────────────┘
Livrable Final
Document à Produire
- Architecture Auto Scaling (schéma)
- Configuration complète (Launch Template + ASG)
- Politiques de scaling (Target Tracking + Scheduled)
- Plan de monitoring (métriques + alertes)
- Résultats des tests (screenshots CloudWatch)
Critères d'Évaluation
| Critère | Points |
|---|---|
| Dimensionnement correct | /15 |
| Configuration ASG complète | /25 |
| Politiques adaptées au scénario | /20 |
| Monitoring et alertes | /15 |
| Tests documentés | /15 |
| Qualité du document | /10 |
| Total | /100 |
Semaine suivante : MODULE 10 - Route 53