Tuần 2 - Ngày 6: Cost Optimization Pillar
Mục tiêu học tập
- Hiểu design principles của Cost Optimization
- Nắm vững các pricing models và cách tối ưu
- Biết tools và techniques để manage costs
1. Định nghĩa Cost Optimization Pillar
Khả năng chạy systems để deliver business value với giá thấp nhất.
5 Focus Areas
- Practice Cloud Financial Management
- Expenditure and Usage Awareness
- Cost-Effective Resources
- Manage Demand and Supply Resources
- Optimize Over Time
2. Design Principles
1. Implement Cloud Financial Management
2. Adopt a consumption model
3. Measure overall efficiency
Business Metrics:
- Cost per transaction
- Cost per user
- Cost per revenue dollar
Not just:
- Total AWS bill
4. Stop spending money on undifferentiated heavy lifting
5. Analyze and attribute expenditure
3. AWS Pricing Models Deep Dive
EC2 Pricing Comparison
Cost Comparison (m5.xlarge, 1 year):
On-Demand: ████████████████████████ $1,400/year (100%)
1yr No Upfront: ████████████████ $980/year (70%)
1yr All Upfront:███████████████ $910/year (65%)
3yr All Upfront:██████████ $590/year (42%)
Spot Instance: ████ $420/year (30%)
Reserved Instance vs Savings Plans
| Aspect | Reserved Instance | Savings Plans |
|---|---|---|
| Commitment | Specific instance | $ amount/hour |
| Flexibility | Limited | High |
| Services | EC2, RDS, etc. | EC2, Lambda, Fargate |
| Discount | Up to 72% | Up to 72% |
| Best for | Stable workloads | Flexible workloads |
Savings Plans Types
Compute Savings Plans:
- Most flexible
- Apply to EC2, Lambda, Fargate
- Any region, instance family, OS
- Up to 66% discount
EC2 Instance Savings Plans:
- Specific instance family in a region
- Any size, tenancy, OS within family
- Up to 72% discount
SageMaker Savings Plans:
- Specific to SageMaker
- Up to 64% discount
Spot Instances Strategies
4. Storage Cost Optimization
S3 Cost Analysis
Storage Costs (per GB/month, us-east-1):
Standard: $0.023 ████████████████████████
Intelligent-Tiering: $0.023 ████████████████████████ (auto-optimize)
Standard-IA: $0.0125 █████████████
One Zone-IA: $0.01 ██████████
Glacier Instant: $0.004 ████
Glacier Flexible: $0.0036 ███
Glacier Deep: $0.00099 █
S3 Lifecycle Optimization
{
"Rules": [{
"ID": "Optimize-Costs",
"Status": "Enabled",
"Transitions": [
{"Days": 30, "StorageClass": "STANDARD_IA"},
{"Days": 90, "StorageClass": "GLACIER"},
{"Days": 365, "StorageClass": "DEEP_ARCHIVE"}
],
"NoncurrentVersionTransitions": [
{"NoncurrentDays": 30, "StorageClass": "GLACIER"}
],
"NoncurrentVersionExpiration": {
"NoncurrentDays": 90
}
}]
}
EBS Cost Optimization
5. Database Cost Optimization
RDS Optimization
1. Right-size instances
- Use Performance Insights
- Check CPU/Memory utilization
2. Reserved Instances
- 1-year or 3-year commitment
- Up to 69% discount
3. Aurora Serverless v2
- Auto-scales 0.5 ACU to 128 ACU
- Pay per ACU-hour
4. Read Replicas
- Offload reads from primary
- May reduce primary instance size
DynamoDB Cost Modes
On-Demand:
- Pay per request
- No capacity planning
- Good for: Unpredictable traffic
Provisioned:
- Provision RCU/WCU
- Lower cost if predictable
- Can use Reserved Capacity
Reserved Capacity:
- Upfront payment
- Up to 77% discount
- 1-year or 3-year
6. Cost Management Tools
AWS Cost Explorer
Features:
- Visualize costs over time
- Forecast future spending
- Identify cost drivers
- Savings Plans recommendations
Reports:
- Monthly costs by service
- Daily costs
- Reserved Instance utilization
- Savings Plans utilization
AWS Budgets
AWS Cost Anomaly Detection
Trusted Advisor
Cost Optimization Checks:
- Idle EC2 instances
- Underutilized EBS volumes
- Unassociated Elastic IPs
- Idle RDS instances
- Low utilization EC2
- Reserved Instance optimization
7. Right-Sizing
Process
Tools
- Compute Optimizer: ML recommendations
- Cost Explorer: Right-sizing recommendations
- CloudWatch: Custom metrics analysis
8. Câu hỏi ôn tập
-
Compute Savings Plans khác EC2 Instance Savings Plans như thế nào?
Xem đáp án
Compute SP: flexible nhất — apply cho EC2 (bất kỳ family/region/OS), Lambda, Fargate. Discount ~66%. EC2 Instance SP: chỉ cho EC2, committed cho một instance family trong một Region cụ thể. Discount cao hơn ~72% nhưng ít flexible hơn. Chọn Compute SP khi có mixed workloads (EC2 + Lambda + Fargate) hoặc cần flexibility thay đổi instance family; EC2 Instance SP khi workload EC2 ổn định và rõ ràng.
-
S3 Intelligent-Tiering hoạt động như thế nào?
Xem đáp án
S3 monitor access frequency của từng object. Object không được access trong 30 ngày → tự động move xuống Infrequent Access tier (giảm storage cost). Nếu được access → move lại Frequent Access ngay. Có thể opt-in thêm Archive tiers (90 ngày, 180 ngày). Không có retrieval fee khi move giữa Frequent/Infrequent tiers. Có monitoring fee (~$0.0025/1000 objects/month) — không worth it cho objects nhỏ (<128 KB, không monitor).
-
gp3 có ưu điểm gì so với gp2?
Xem đáp án
gp3: (1) Rẻ hơn ~20% for same storage size, (2) IOPS độc lập với size — 3,000 IOPS baseline kể cả volume 1 GB (gp2 chỉ có 3 IOPS/GB), (3) Provisioned IOPS lên đến 16,000 và throughput 1,000 MB/s không cần tăng size, (4) Không bị "burst credit" mechanism phức tạp như gp2. Migrate từ gp2 sang gp3 không có downtime — dùng Elastic Volume modification.
-
AWS Budgets có thể thực hiện actions gì?
Xem đáp án
Budget Actions (tự động): (1) Apply IAM policy — giới hạn quyền deploy resources khi budget hit, (2) Attach SCP — block actions ở Organizations level, (3) Target specific EC2/RDS instances — stop instances. Alerts (thông báo): email notifications, SNS topics. Budget Actions giúp enforce cost controls tự động — không cần manual intervention khi budget bị vượt. Kết hợp với SNS → Lambda để custom actions.
-
Right-sizing nên dựa trên metrics nào?
Xem đáp án
(1) CPU utilization — EC2 CPU < 40% sustained → downsize instance type, (2) Memory utilization — dùng CloudWatch Agent, (3) Network throughput — bandwidth needs, (4) Disk IOPS/throughput — EBS metrics, (5) Application-level metrics — response time, error rate. AWS Compute Optimizer analyze 14 ngày metrics và recommend optimal instance type với performance + cost trade-offs. Tránh right-size dựa trên peak only — look at P95/P99 và average.
9. Bài tập thực hành
- Enable Cost Explorer và phân tích chi phí
- Create AWS Budget với alert
- Review Trusted Advisor cost recommendations
- Apply S3 Lifecycle policy
Tài liệu tham khảo chính thức
Ngày tiếp theo: Quiz tổng kết Tuần 2