Lab : Optimisation des Coûts
Objectif
Analyser une infrastructure AWS et proposer des recommandations d'optimisation avec justifications et estimations d'économies.
Scénario
Contexte
TechStartup Inc. dépense $15,000/mois sur AWS et souhaite réduire ses coûts de 30% sans impacter les performances.
Infrastructure Actuelle
┌─────────────────────────────────────────────────────────────┐
│ INFRASTRUCTURE TECHSTARTUP │
├─────────────────────────────────────────────────────────────┤
│ │
│ COMPUTE ($8,500/mois) │
│ ───────────────────── │
│ • 10x m5.xlarge (production web) 24/7 $1,400 │
│ • 5x m5.large (production API) 24/7 $350 │
│ • 3x r5.2xlarge (production DB) 24/7 $900 │
│ • 5x m5.large (staging) 24/7 $350 │
│ • 8x c5.xlarge (batch processing) 24/7 $1,100 │
│ • 4x t3.large (dev) 24/7 $250 │
│ • 2x m5.xlarge (CI/CD runners) 24/7 $280 │
│ Autres (Lambda, misc) $3,870 │
│ │
│ STORAGE ($3,000/mois) │
│ ───────────────────── │
│ • EBS gp2 volumes 5 TB $500 │
│ • S3 Standard 20 TB $460 │
│ • EBS Snapshots 10 TB $500 │
│ • RDS Storage 2 TB $200 │
│ • Backup/Archive $1,340 │
│ │
│ NETWORK ($2,500/mois) │
│ ───────────────────── │
│ • NAT Gateways (3x) $300 │
│ • Data Transfer $2,000 │
│ • Load Balancers (5x) $200 │
│ │
│ AUTRES ($1,000/mois) │
│ ─────────────────── │
│ • CloudWatch, Secrets Manager, etc. │
│ │
│ TOTAL : $15,000/mois │
│ │
└─────────────────────────────────────────────────────────────┘
Métriques d'Utilisation
| Ressource | CPU Avg | Mem Avg | Heures actives |
|---|---|---|---|
| Web (prod) | 35% | 45% | 24/7 |
| API (prod) | 40% | 50% | 24/7 |
| DB (prod) | 65% | 70% | 24/7 |
| Staging | 15% | 20% | 9h-18h weekdays |
| Batch | 80% | 60% | 2h/jour (nuit) |
| Dev | 10% | 15% | 9h-18h weekdays |
| CI/CD | 25% | 30% | Variable |
Partie 1 : Analyse des Coûts
Exercice 1.1 : Identification des Problèmes
Identifiez les 5 principales sources de gaspillage :
| # | Ressource | Problème | Impact Estimé |
|---|---|---|---|
| 1 | ? | ? | $?/mois |
| 2 | ? | ? | $?/mois |
| 3 | ? | ? | $?/mois |
| 4 | ? | ? | $?/mois |
| 5 | ? | ? | $?/mois |
💡 Solution
| # | Ressource | Problème | Impact Estimé |
|---|---|---|---|
| 1 | Staging 24/7 | Devrait être arrêté hors heures | $250/mois |
| 2 | Dev 24/7 | Idem, gaspillage nuit/weekend | $180/mois |
| 3 | Batch 24/7 | Ne tourne que 2h/jour | $900/mois |
| 4 | Web surdimensionné | CPU 35% → right-size | $400/mois |
| 5 | Pas de RI/SP | Tout en On-Demand | $2,500/mois |
Exercice 1.2 : Analyse par Tag
Le tagging actuel est incomplet. Proposez une stratégie de tagging :
| Tag | Obligatoire | Valeurs Possibles |
|---|---|---|
| ? | Oui/Non | ? |
| ? | Oui/Non | ? |
| ? | Oui/Non | ? |
| ? | Oui/Non | ? |
💡 Solution
| Tag | Obligatoire | Valeurs Possibles |
|---|---|---|
| Environment | Oui | production, staging, development |
| Project | Oui | web-app, api, batch, infra |
| Owner | Oui | team-frontend, team-backend, team-data |
| CostCenter | Oui | CC-PROD, CC-DEV, CC-OPS |
| AutoShutdown | Non | true, false |
| ExpiryDate | Non | YYYY-MM-DD |
Partie 2 : Plan d'Optimisation
Exercice 2.1 : Right-Sizing
Proposez de nouveaux types d'instances :
| Actuel | Nouveau | Justification | Économie |
|---|---|---|---|
| m5.xlarge (web) | ? | ? | $? |
| m5.large (staging) | ? | ? | $? |
| t3.large (dev) | ? | ? | $? |
💡 Solution
| Actuel | Nouveau | Justification | Économie |
|---|---|---|---|
| 10x m5.xlarge (web) | 10x m5.large | CPU 35% OK avec large | $700/mois |
| 5x m5.large (staging) | 3x t3.medium | Staging utilisé peu, burstable OK | $280/mois |
| 4x t3.large (dev) | 4x t3.medium | Dev très sous-utilisé | $100/mois |
Exercice 2.2 : Scheduling
Configurez l'arrêt automatique des environnements non-prod :
# Complétez le script de scheduling
# Staging : arrêt 18h, démarrage 9h (weekdays)
# Dev : arrêt 19h, démarrage 8h (weekdays)
# EventBridge rule pour arrêt staging à 18h
aws events put-rule \
--name stop-staging-evening \
--schedule-expression "cron(_______________)" \
--state ENABLED
# Lambda ou SSM Automation target
# ...
💡 Solution
# Arrêt staging à 18h UTC, Lun-Ven
aws events put-rule \
--name stop-staging-evening \
--schedule-expression "cron(0 18 ? * MON-FRI *)" \
--state ENABLED
# Démarrage staging à 9h UTC, Lun-Ven
aws events put-rule \
--name start-staging-morning \
--schedule-expression "cron(0 9 ? * MON-FRI *)" \
--state ENABLED
# Arrêt dev à 19h UTC, Lun-Ven
aws events put-rule \
--name stop-dev-evening \
--schedule-expression "cron(0 19 ? * MON-FRI *)" \
--state ENABLED
# Démarrage dev à 8h UTC, Lun-Ven
aws events put-rule \
--name start-dev-morning \
--schedule-expression "cron(0 8 ? * MON-FRI *)" \
--state ENABLED
Économie staging : 14h/jour × 5 jours × 4 semaines = 280h/mois (vs 720h) → Réduction ~60% = $210/mois
Économie dev : 13h/jour × 5 jours × 4 semaines = 260h/mois → Réduction ~65% = $160/mois
Exercice 2.3 : Spot Instances
Identifiez les workloads candidats pour Spot :
| Workload | Candidat Spot ? | Justification |
|---|---|---|
| Web (prod) | ? | ? |
| Batch processing | ? | ? |
| CI/CD runners | ? | ? |
💡 Solution
| Workload | Candidat Spot ? | Justification |
|---|---|---|
| Web (prod) | ❌ Non | Critique, ne peut pas être interrompu |
| Batch processing | ✅ Oui | Exécution courte, peut reprendre, 60-90% économie |
| CI/CD runners | ✅ Oui | Tolérant aux interruptions, jobs peuvent retry |
Économies Spot :
- Batch : $1,100 × 70% = $770/mois d'économie
- CI/CD : $280 × 65% = $180/mois d'économie
Exercice 2.4 : Reserved Instances / Savings Plans
Calculez la couverture optimale :
Workload stable 24/7 (candidat RI/SP) :
- Production web : 10 instances → ?
- Production API : 5 instances → ?
- Production DB : 3 instances → ?
Calcul économie avec 1-year Savings Plan (-30%) :
💡 Solution
Workload stable (après right-sizing) :
- Web : 10x m5.large = ~$700/mois
- API : 5x m5.large = ~$350/mois
- DB : 3x r5.2xlarge = ~$900/mois
Total éligible RI/SP : $1,950/mois
Avec Compute Savings Plan 1-year (-30%) :
- Économie : $1,950 × 30% = $585/mois
Engagement mensuel : $1,365/mois (vs $1,950)
Partie 3 : Optimisation Storage
Exercice 3.1 : Migration gp2 → gp3
EBS gp2 actuel : 5 TB = $500/mois
Migration vers gp3 : calcul économie
💡 Solution
gp2 pricing : $0.10/GB/mois = 5000 × $0.10 = $500/mois
gp3 pricing : $0.08/GB/mois = 5000 × $0.08 = $400/mois
Économie : $100/mois (20%)
Plus : gp3 offre 3000 IOPS de base gratuits vs gp2 qui scale avec la taille.
Exercice 3.2 : S3 Lifecycle Policies
Proposez des règles de lifecycle pour S3 :
| Classe | Après | Données | Économie |
|---|---|---|---|
| Standard | 0 jours | Actives | Référence |
| ? | ? | ? | ? |
| ? | ? | ? | ? |
💡 Solution
| Classe | Après | Données | Coût/GB |
|---|---|---|---|
| Standard | 0 jours | < 30 jours | $0.023 |
| Standard-IA | 30 jours | 30-90 jours | $0.0125 |
| Glacier | 90 jours | > 90 jours | $0.004 |
Estimation avec 20 TB :
- Si 30% actif, 40% IA, 30% archive
- Standard : 6 TB × $0.023 = $138
- IA : 8 TB × $0.0125 = $100
- Glacier : 6 TB × $0.004 = $24
- Total : $262/mois vs $460 = $198 économie (43%)
Partie 4 : Synthèse
Exercice 4.1 : Tableau Récapitulatif
Complétez le tableau des économies :
| Catégorie | Action | Économie/mois | % |
|---|---|---|---|
| Compute | Right-sizing | $? | ?% |
| Compute | Scheduling | $? | ?% |
| Compute | Spot | $? | ?% |
| Compute | Savings Plans | $? | ?% |
| Storage | gp2→gp3 | $? | ?% |
| Storage | S3 Lifecycle | $? | ?% |
| TOTAL | $? | ?% |
💡 Solution
| Catégorie | Action | Économie/mois | % du total |
|---|---|---|---|
| Compute | Right-sizing | $1,080 | 7.2% |
| Compute | Scheduling | $370 | 2.5% |
| Compute | Spot (batch+CI) | $950 | 6.3% |
| Compute | Savings Plans | $585 | 3.9% |
| Storage | gp2→gp3 | $100 | 0.7% |
| Storage | S3 Lifecycle | $198 | 1.3% |
| TOTAL | $3,283 | 21.9% |
Coût initial : $15,000/mois Coût optimisé : $11,717/mois Économie : $3,283/mois soit ~22%
Pour atteindre 30%, actions supplémentaires :
- Revoir architecture (serverless ?)
- Négocier EDP avec AWS
- Optimiser data transfer
Livrable Final
Document à Produire
- Analyse de l'existant avec identification des gaspillages
- Stratégie de tagging complète
- Plan d'optimisation détaillé avec calculs
- Tableau récapitulatif des économies
- Recommandations prioritaires (quick wins vs long terme)
Critères d'Évaluation
| Critère | Points |
|---|---|
| Analyse correcte des gaspillages | /20 |
| Stratégie de tagging | /15 |
| Calculs d'économies | /25 |
| Plan actionnable | /25 |
| Qualité du document | /15 |
| Total | /100 |
Semaine suivante : MODULE 15 - CloudFormation