Lab: Cost Optimization
Objective
Analyze an AWS infrastructure and propose optimization recommendations with justifications and savings estimates.
Scenario
Context
TechStartup Inc. spends $15,000/month on AWS and wants to reduce costs by 30% without impacting performance.
Current Infrastructure
┌─────────────────────────────────────────────────────────────┐
│ TECHSTARTUP INFRASTRUCTURE │
├─────────────────────────────────────────────────────────────┤
│ │
│ COMPUTE ($8,500/month) │
│ ───────────────────── │
│ • 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 │
│ Others (Lambda, misc) $3,870 │
│ │
│ STORAGE ($3,000/month) │
│ ───────────────────── │
│ • 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/month) │
│ ───────────────────── │
│ • NAT Gateways (3x) $300 │
│ • Data Transfer $2,000 │
│ • Load Balancers (5x) $200 │
│ │
│ OTHERS ($1,000/month) │
│ ─────────────────── │
│ • CloudWatch, Secrets Manager, etc. │
│ │
│ TOTAL: $15,000/month │
│ │
└─────────────────────────────────────────────────────────────┘
Usage Metrics
| Resource | CPU Avg | Mem Avg | Active Hours |
|---|---|---|---|
| Web (prod) | 35% | 45% | 24/7 |
| API (prod) | 40% | 50% | 24/7 |
| DB (prod) | 65% | 70% | 24/7 |
| Staging | 15% | 20% | 9am-6pm weekdays |
| Batch | 80% | 60% | 2h/day (night) |
| Dev | 10% | 15% | 9am-6pm weekdays |
| CI/CD | 25% | 30% | Variable |
Part 1: Cost Analysis
Exercise 1.1: Problem Identification
Identify the top 5 sources of waste:
| # | Resource | Problem | Estimated Impact |
|---|---|---|---|
| 1 | ? | ? | $?/month |
| 2 | ? | ? | $?/month |
| 3 | ? | ? | $?/month |
| 4 | ? | ? | $?/month |
| 5 | ? | ? | $?/month |
💡 Solution
| # | Resource | Problem | Estimated Impact |
|---|---|---|---|
| 1 | Staging 24/7 | Should be stopped outside hours | $250/month |
| 2 | Dev 24/7 | Same, waste at night/weekend | $180/month |
| 3 | Batch 24/7 | Runs only 2h/day | $900/month |
| 4 | Oversized Web | CPU 35% → right-size | $400/month |
| 5 | No RI/SP | All On-Demand | $2,500/month |
Exercise 1.2: Tagging Analysis
Current tagging is incomplete. Propose a tagging strategy:
| Tag | Mandatory | Possible Values |
|---|---|---|
| ? | Yes/No | ? |
| ? | Yes/No | ? |
| ? | Yes/No | ? |
| ? | Yes/No | ? |
💡 Solution
| Tag | Mandatory | Possible Values |
|---|---|---|
| Environment | Yes | production, staging, development |
| Project | Yes | web-app, api, batch, infra |
| Owner | Yes | team-frontend, team-backend, team-data |
| CostCenter | Yes | CC-PROD, CC-DEV, CC-OPS |
| AutoShutdown | No | true, false |
| ExpiryDate | No | YYYY-MM-DD |
Part 2: Optimization Plan
Exercise 2.1: Right-Sizing
Propose new instance types:
| Current | New | Justification | Savings |
|---|---|---|---|
| m5.xlarge (web) | ? | ? | $? |
| m5.large (staging) | ? | ? | $? |
| t3.large (dev) | ? | ? | $? |
💡 Solution
| Current | New | Justification | Savings |
|---|---|---|---|
| 10x m5.xlarge (web) | 10x m5.large | CPU 35% OK with large | $700/month |
| 5x m5.large (staging) | 3x t3.medium | Staging used little, burstable OK | $280/month |
| 4x t3.large (dev) | 4x t3.medium | Dev very underutilized | $100/month |
Exercise 2.2: Scheduling
Configure automatic shutdown of non-prod environments:
# Complete the scheduling script
# Staging: stop 6pm, start 9am (weekdays)
# Dev: stop 7pm, start 8am (weekdays)
# EventBridge rule for stopping staging at 6pm
aws events put-rule \
--name stop-staging-evening \
--schedule-expression "cron(_______________)" \
--state ENABLED
# Lambda or SSM Automation target
# ...
💡 Solution
# Stop staging at 6pm UTC, Mon-Fri
aws events put-rule \
--name stop-staging-evening \
--schedule-expression "cron(0 18 ? * MON-FRI *)" \
--state ENABLED
# Start staging at 9am UTC, Mon-Fri
aws events put-rule \
--name start-staging-morning \
--schedule-expression "cron(0 9 ? * MON-FRI *)" \
--state ENABLED
# Stop dev at 7pm UTC, Mon-Fri
aws events put-rule \
--name stop-dev-evening \
--schedule-expression "cron(0 19 ? * MON-FRI *)" \
--state ENABLED
# Start dev at 8am UTC, Mon-Fri
aws events put-rule \
--name start-dev-morning \
--schedule-expression "cron(0 8 ? * MON-FRI *)" \
--state ENABLED
Staging savings: 14h/day × 5 days × 4 weeks = 280h/month (vs 720h) → Reduction ~60% = $210/month
Dev savings: 13h/day × 5 days × 4 weeks = 260h/month → Reduction ~65% = $160/month
Exercise 2.3: Spot Instances
Identify workloads suitable for Spot:
| Workload | Spot Candidate? | Justification |
|---|---|---|
| Web (prod) | ? | ? |
| Batch processing | ? | ? |
| CI/CD runners | ? | ? |
💡 Solution
| Workload | Spot Candidate? | Justification |
|---|---|---|
| Web (prod) | ❌ No | Critical, cannot be interrupted |
| Batch processing | ✅ Yes | Short execution, can resume, 60-90% savings |
| CI/CD runners | ✅ Yes | Tolerant to interruptions, jobs can retry |
Spot savings:
- Batch: $1,100 × 70% = $770/month savings
- CI/CD: $280 × 65% = $180/month savings
Exercise 2.4: Reserved Instances / Savings Plans
Calculate optimal coverage:
Stable 24/7 workload (RI/SP candidate):
- Production web: 10 instances → ?
- Production API: 5 instances → ?
- Production DB: 3 instances → ?
Savings calculation with 1-year Savings Plan (-30%):
💡 Solution
Stable workload (after right-sizing):
- Web: 10x m5.large = ~$700/month
- API: 5x m5.large = ~$350/month
- DB: 3x r5.2xlarge = ~$900/month
Total eligible for RI/SP: $1,950/month
With 1-year Compute Savings Plan (-30%):
- Savings: $1,950 × 30% = $585/month
Monthly commitment: $1,365/month (vs $1,950)
Part 3: Storage Optimization
Exercise 3.1: Migration gp2 → gp3
Current EBS gp2: 5 TB = $500/month
Migration to gp3: calculate savings
💡 Solution
gp2 pricing: $0.10/GB/month = 5000 × $0.10 = $500/month
gp3 pricing: $0.08/GB/month = 5000 × $0.08 = $400/month
Savings: $100/month (20%)
Plus: gp3 offers 3000 IOPS base for free vs gp2 which scales with size.
Exercise 3.2: S3 Lifecycle Policies
Propose lifecycle rules for S3:
| Class | After | Data | Savings |
|---|---|---|---|
| Standard | 0 days | Active | Reference |
| ? | ? | ? | ? |
| ? | ? | ? | ? |
💡 Solution
| Class | After | Data | Cost/GB |
|---|---|---|---|
| Standard | 0 days | < 30 days | $0.023 |
| Standard-IA | 30 days | 30-90 days | $0.0125 |
| Glacier | 90 days | > 90 days | $0.004 |
Estimate with 20 TB:
- If 30% active, 40% IA, 30% archive
- Standard: 6 TB × $0.023 = $138
- IA: 8 TB × $0.0125 = $100
- Glacier: 6 TB × $0.004 = $24
- Total: $262/month vs $460 = $198 savings (43%)
Part 4: Summary
Exercise 4.1: Summary Table
Complete the savings table:
| Category | Action | Savings/month | % |
|---|---|---|---|
| Compute | Right-sizing | $? | ?% |
| Compute | Scheduling | $? | ?% |
| Compute | Spot | $? | ?% |
| Compute | Savings Plans | $? | ?% |
| Storage | gp2→gp3 | $? | ?% |
| Storage | S3 Lifecycle | $? | ?% |
| TOTAL | $? | ?% |
💡 Solution
| Category | Action | Savings/month | % of 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% |
Initial cost: $15,000/month Optimized cost: $11,717/month Savings: $3,283/month or ~22%
To reach 30%, additional actions:
- Review architecture (serverless?)
- Negotiate EDP with AWS
- Optimize data transfer
Final Deliverable
Document to Produce
- Existing Analysis with waste identification
- Complete Tagging Strategy
- Detailed Optimization Plan with calculations
- Summary Table of savings
- Priority Recommendations (quick wins vs long term)
Evaluation Criteria
| Criterion | Points |
|---|---|
| Correct waste analysis | /20 |
| Tagging strategy | /15 |
| Savings calculations | /25 |
| Actionable plan | /25 |
| Document quality | /15 |
| Total | /100 |
Next week: MODULE 15 - CloudFormation