</>Học Dev
Bài học

Tuần 2 - Ngày 2: EC2 Pricing Models

Tuần 2 – Ngày 2

Tuần 2 - Ngày 2: EC2 Pricing Models

Mục tiêu học tập

  • Hiểu chi tiết 5 pricing models EC2
  • Biết khi nào dùng RI vs Savings Plans vs Spot
  • Hiểu Dedicated Host vs Dedicated Instance
  • Áp dụng pricing model cho từng workload pattern

1. Tổng quan 5 Pricing Models

ModelDiscountCommitmentHoàn lạiUse case
On-Demand0%KhôngTest, unpredictable, short-term
Reserved Instance (RI)Lên đến 72%1y / 3yMarketplace bán lại đượcSteady workload
Savings Plans (SP)Lên đến 72%1y / 3yKhông hoàn lạiFlexible commitment
Spot InstanceLên đến 90%KhôngEC2 có thể bị reclaimFault-tolerant, batch
Dedicated HostOn-demand or RILicense BYOL, compliance

2. On-Demand

Đặc điểm

  • Trả theo giây (Linux, min 60s) hoặc giờ (Windows, RHEL, SLES)
  • Không commitment
  • Đắt nhất nhưng linh hoạt nhất

Use case

  • Test/development ngắn hạn
  • Workload không dự đoán được
  • Migration phase đầu (chưa biết exact requirement)
  • Đỉnh tải tạm thời (kèm RI cho baseline)

3. Reserved Instance (RI)

Term

  • 1 năm hoặc 3 năm
  • 3 năm tiết kiệm hơn 1 năm

Payment options

  • All Upfront (AURI): Trả hết → discount lớn nhất
  • Partial Upfront (PURI): Trả 1 phần → discount vừa
  • No Upfront (NURI): Trả hàng tháng → discount thấp hơn

Offering Class

ClassĐổi instance familyĐổi OS, tenancyResell on Marketplace
Standard RIKhôngKhông
Convertible RI (cùng giá trị trở lên)Không

Scope

  • Regional RI (mặc định): Áp dụng cho any AZ trong Region, không reserve capacity
  • Zonal RI: Áp dụng 1 AZ cụ thể, reserve capacity (đảm bảo có instance khi cần)

Use case

  • Workload chạy 24/7 ổn định trong > 1 năm
  • Database production
  • Web servers ổn định (cùng baseline + ASG cho peak)

Reserved Instance Marketplace

  • Bán RI Standard không còn cần
  • Buyer có thể mua RI < 1 năm remaining từ Marketplace

4. Savings Plans (SP)

Định nghĩa

Savings Plans = commit $X/hour trong 1 hoặc 3 năm, nhận discount trên usage tương ứng.

3 loại SP

TypeÁp dụng choFlexibilityDiscount
Compute Savings PlansEC2 (mọi family, Region), Fargate, LambdaCao nhấtUp to 66%
EC2 Instance Savings PlansEC2 1 family + 1 RegionĐổi size/OS trong familyUp to 72%
SageMaker Savings PlansSageMakerUp to 64%

So sánh RI vs Savings Plans

Reserved InstanceSavings Plans
CommitmentInstance attributes (type, OS, region)$/hour spend
Apply toEC2, RDS, ElastiCache, OpenSearch, RedshiftEC2 + Fargate + Lambda (Compute SP)
FlexibilityConvertible RI cho phép đổiCao (Compute SP đổi family, region)
ResellStandard RI bán đượcKhông bán được

Khuyến nghị: Compute Savings Plans cho EC2 + serverless workload.

5. Spot Instances

Định nghĩa

Spot = mua spare EC2 capacity với discount lên đến 90% so với On-Demand, nhưng AWS có thể reclaim với 2-min warning.

Spot Price

  • Giá thay đổi theo cung-cầu
  • Bạn set maximum price (tự bid)
  • Nếu Spot Price ≤ max price → instance chạy
  • Nếu Spot Price > max price → instance bị terminate

Spot Instance Interruption Behavior

3 options khi bị reclaim:

  • Terminate (mặc định)
  • Stop (giữ EBS)
  • Hibernate (lưu RAM)

Spot Fleet vs Spot Request

Spot RequestSpot Fleet
Số instance1Multiple, mix On-Demand + Spot
Allocation strategylowest-price, diversified, capacity-optimized

Allocation Strategy (cho Spot Fleet & ASG mixed)

  • lowestPrice: Pool với giá thấp nhất
  • diversified: Phân tán qua nhiều pool
  • capacityOptimized: Pool ít bị interrupt nhất (recommended)
  • priceCapacityOptimized: Cân bằng price + capacity

Use case Spot

  • Batch processing
  • Big data (EMR, Spark)
  • CI/CD workers
  • Containerized stateless workload (ECS/EKS)
  • Image/video rendering
  • KHÔNG dùng cho: Database, single-instance critical apps

Spot Block (đã deprecated)

  • Trước đây: Spot reserve 1-6 hours không bị reclaim
  • AWS đã ngừng Spot Block từ 2021 cho new customers. Hiện chỉ còn Spot Request thông thường.

6. Dedicated Host

Định nghĩa

Dedicated Host = physical server vật lý dành riêng cho 1 account, có visibility xuống socket/core level.

Đặc điểm

  • Bạn trả tiền theo host (not theo instance)
  • Visibility vào CPU socket, physical cores
  • License BYOL (Bring Your Own License) cho Windows Server, SQL Server, Oracle
  • Compliance (regulatory requires dedicated hardware)
  • Hỗ trợ Host Affinity: instance luôn launch trên cùng host khi stop/start

Pricing

  • On-Demand Dedicated Host: $/hour
  • Reserved Dedicated Host: 1y/3y term, discount lên đến ~70%

7. Dedicated Instance

Định nghĩa

Dedicated Instance = EC2 instance chạy trên hardware dedicated cho 1 account, nhưng bạn không có visibility xuống socket.

So sánh Dedicated Host vs Dedicated Instance

Dedicated HostDedicated Instance
PricingPer hostPer instance
Visibility hardwareCó (socket, core)Không
BYOLHạn chế
Same host across stop/startCó (Host Affinity)Không guaranteed
Use caseStrict compliance, BYOLCompliance vừa phải

8. Capacity Reservations

Định nghĩa

On-Demand Capacity Reservation (ODCR) = reserve EC2 capacity ở 1 AZ cụ thể, không discount giá, chỉ đảm bảo có capacity khi cần.

Use case

  • Đảm bảo capacity cho event quan trọng (Black Friday)
  • DR scenarios (đảm bảo có capacity để failover)
  • Combination: ODCR + Savings Plans = capacity + discount

So sánh

Zonal RIOn-Demand Capacity Reservation
DiscountKhông
Capacity guarantee
Commitment1y/3yKhông (có thể cancel anytime)

9. So sánh tổng hợp — Chọn pricing nào?

WorkloadpatternRecommendedpricingSteady-state,24/7,>1yearReservedInstance3yAURISteady+biếtfamily/regionEC2InstanceSavingsPlansFlexibleworkload,multi-serviceComputeSavingsPlansUnpredictable,shortburstsOn-DemandBatch,fault-tolerantSpotInstancesNeedcapacityguaranteeODCR+SavingsPlansBYOLWindows/OracleDedicatedHostCompliancededicatedHWDedicatedHost/Instance

Best practice mix

Baseline workload (24/7)   → RI hoặc Compute SP
Variable workload           → On-Demand
Burst/batch                 → Spot

Ví dụ web app:

  • 10 instances baseline → 10 RI 3-year (75% off)
  • 5 instances peak hours → On-Demand
  • Background processing → Spot

10. Bài toán so sánh chi phí

Scenario: EC2 t3.medium chạy 24/7, 3 năm, us-east-1.

PricingGiá $/hourTổng 3 nămTiết kiệm
On-Demand$0.0416~$1,0930%
RI 1-year NURI$0.029~$76230%
RI 3-year AURI$0.0134~$35268%
Compute SP 3-year AURI$0.014~$36866%
Spot (avg)$0.013~$34169% (nhưng có thể bị reclaim)

Giá thay đổi theo region và thời điểm — đây chỉ là minh họa.

Câu hỏi ôn tập

  1. RI Standard và Convertible khác nhau ở điểm gì?

    Xem đáp án

    Standard RI: discount cao hơn (lên đến 72%), không thể đổi instance family/OS/tenancy trong thời hạn, có thể bán lại trên RI Marketplace. Convertible RI: discount thấp hơn (~54%), có thể exchange sang RI khác cùng hoặc cao hơn giá trị (đổi instance family, OS, tenancy, Region), không bán lại được. Chọn Standard khi workload ổn định rõ ràng; Convertible khi cần flexibility.

  2. Khi nào dùng Compute Savings Plans thay vì EC2 Instance Savings Plans?

    Xem đáp án

    Compute Savings Plans áp dụng cho EC2 (bất kỳ instance family, Region, OS, tenancy), Lambda, và Fargate — flexible nhất nhưng discount thấp hơn (~66%). EC2 Instance Savings Plans chỉ áp dụng cho một instance family trong một Region cụ thể — discount cao hơn (~72%) nhưng ít flexible. Chọn Compute SP khi có workload Lambda/Fargate đáng kể hoặc cần thay đổi instance family; EC2 Instance SP khi workload EC2 ổn định và biết rõ instance family.

  3. Spot Instance bị AWS reclaim sau bao lâu warning?

    Xem đáp án

    2 phút (120 giây) warning trước khi AWS reclaim. Spot Instance gửi interruption notice qua Instance Metadata và EventBridge. Ứng dụng phải handle gracefully trong 2 phút này: checkpoint work, drain connections, save state. Spot phù hợp cho batch jobs, data processing, stateless workloads — không phù hợp cho databases hay stateful apps không chịu được interruption.

  4. Use case nào BẮT BUỘC dùng Dedicated Host thay vì Dedicated Instance?

    Xem đáp án

    BYOL (Bring Your Own License) cho phần mềm tính phí theo physical server hoặc per-socket/per-core — ví dụ Windows Server, SQL Server, Oracle Database với license models dựa trên physical host specs. Dedicated Host cung cấp visibility về số cores và socket trên physical server cụ thể — cần thiết để comply với license terms. Dedicated Instance chỉ đảm bảo isolated hardware nhưng không cung cấp host-level visibility.

  5. On-Demand Capacity Reservation có cho discount giá không?

    Xem đáp án

    Không. On-Demand Capacity Reservation đảm bảo reserved capacity trong một AZ cụ thể nhưng tính phí On-Demand rate — không có discount. Để vừa có capacity reservation vừa có discount, kết hợp với Zonal Reserved Instance hoặc Savings Plans — chúng tự động áp dụng discount lên capacity reservation matching. Hữu ích cho disaster recovery scenarios cần đảm bảo capacity sẵn sàng.

Bài tập thực hành

  • Vào AWS Console → EC2 → Reserved Instances → xem RI Marketplace
  • Tính tổng chi phí 3 năm cho 1 m5.xlarge với từng pricing model qua Pricing Calculator
  • Launch 1 Spot Instance với max price = giá On-Demand, observe Spot Price trong 24h
  • Tạo Compute Savings Plans 1-year, $1/hour commitment (lưu ý: thử thôi, cancel nếu không cần)

Tài liệu tham khảo chính thức


Tiếp theo: EC2 Storage (EBS)