Lab 1.5: DynamoDB GSI/LSI + Query vs Scan
Skills covered: 1.3.1, 1.3.2, 1.3.3, 1.3.4
Mục tiêu
- Tạo table với GSI và LSI
- So sánh Query vs Scan performance
Bước 1: Tạo Table với Indexes
- Table:
Products, PK: category, SK: productId - LSI:
category-price-index (SK: price) - GSI:
brand-index (PK: brand, SK: createdAt)
Bước 2: Load 100+ Sample Items
- BatchWriteItem với diverse categories, brands, prices
Bước 3: Query vs Scan
- Query by category → nhanh, ít RCU
- Scan toàn bộ table → chậm, nhiều RCU
- So sánh ConsumedCapacity
Bước 4: Index Queries
- Query LSI: Products sorted by price
- Query GSI: Products by brand
- Strongly consistent trên LSI ✅ vs GSI ❌
Bước 5: FilterExpression
- Query + FilterExpression → observe RCU KHÔNG giảm
Kiểm tra kiến thức