Skip to main content

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​

ResourceCPU AvgMem AvgActive Hours
Web (prod)35%45%24/7
API (prod)40%50%24/7
DB (prod)65%70%24/7
Staging15%20%9am-6pm weekdays
Batch80%60%2h/day (night)
Dev10%15%9am-6pm weekdays
CI/CD25%30%Variable

Part 1: Cost Analysis​

Exercise 1.1: Problem Identification​

Identify the top 5 sources of waste:

#ResourceProblemEstimated Impact
1??$?/month
2??$?/month
3??$?/month
4??$?/month
5??$?/month
💡 Solution
#ResourceProblemEstimated Impact
1Staging 24/7Should be stopped outside hours$250/month
2Dev 24/7Same, waste at night/weekend$180/month
3Batch 24/7Runs only 2h/day$900/month
4Oversized WebCPU 35% → right-size$400/month
5No RI/SPAll On-Demand$2,500/month

Exercise 1.2: Tagging Analysis​

Current tagging is incomplete. Propose a tagging strategy:

TagMandatoryPossible Values
?Yes/No?
?Yes/No?
?Yes/No?
?Yes/No?
💡 Solution
TagMandatoryPossible Values
EnvironmentYesproduction, staging, development
ProjectYesweb-app, api, batch, infra
OwnerYesteam-frontend, team-backend, team-data
CostCenterYesCC-PROD, CC-DEV, CC-OPS
AutoShutdownNotrue, false
ExpiryDateNoYYYY-MM-DD

Part 2: Optimization Plan​

Exercise 2.1: Right-Sizing​

Propose new instance types:

CurrentNewJustificationSavings
m5.xlarge (web)??$?
m5.large (staging)??$?
t3.large (dev)??$?
💡 Solution
CurrentNewJustificationSavings
10x m5.xlarge (web)10x m5.largeCPU 35% OK with large$700/month
5x m5.large (staging)3x t3.mediumStaging used little, burstable OK$280/month
4x t3.large (dev)4x t3.mediumDev 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:

WorkloadSpot Candidate?Justification
Web (prod)??
Batch processing??
CI/CD runners??
💡 Solution
WorkloadSpot Candidate?Justification
Web (prod)❌ NoCritical, cannot be interrupted
Batch processing✅ YesShort execution, can resume, 60-90% savings
CI/CD runners✅ YesTolerant 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:

ClassAfterDataSavings
Standard0 daysActiveReference
????
????
💡 Solution
ClassAfterDataCost/GB
Standard0 days< 30 days$0.023
Standard-IA30 days30-90 days$0.0125
Glacier90 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:

CategoryActionSavings/month%
ComputeRight-sizing$??%
ComputeScheduling$??%
ComputeSpot$??%
ComputeSavings Plans$??%
Storagegp2→gp3$??%
StorageS3 Lifecycle$??%
TOTAL$??%
💡 Solution
CategoryActionSavings/month% of total
ComputeRight-sizing$1,0807.2%
ComputeScheduling$3702.5%
ComputeSpot (batch+CI)$9506.3%
ComputeSavings Plans$5853.9%
Storagegp2→gp3$1000.7%
StorageS3 Lifecycle$1981.3%
TOTAL$3,28321.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​

  1. Existing Analysis with waste identification
  2. Complete Tagging Strategy
  3. Detailed Optimization Plan with calculations
  4. Summary Table of savings
  5. Priority Recommendations (quick wins vs long term)

Evaluation Criteria​

CriterionPoints
Correct waste analysis/20
Tagging strategy/15
Savings calculations/25
Actionable plan/25
Document quality/15
Total/100

Next week: MODULE 15 - CloudFormation