Thuta Learning
ရှာဖွေရန်
AdvancedDevOpsbeginner

DynamoDB Basics

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

ဒီခန်းပြီးရင် ဘာတတ်သွားမလဲ

  • DynamoDB Basics ကို ကြောက်စရာမလိုအောင် နားလည်မယ်
  • ကိုယ်တိုင် AWS CLI/Console ကို run ကြည့်တတ်မယ်
  • Real project ထဲမှာ ဒီ concept ကို ချက်ချင်း အသုံးချတတ်မယ်

ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်

RDS (Intermediate chapter) က relational database (table, schema, SQL query) ဖြစ်ပါတယ် — DynamoDB ကတော့ NoSQL database ပါ, schema fixed မလိုအပ်ပါ (item တစ်ခုချင်းစီက attribute ကွဲပြားနိုင်ပါတယ်)။ Primary Key (Partition Key, optional Sort Key) ကို ကြိုတင်ဒီဇိုင်းလုပ်ရပေမယ့်, attribute အခြားတွေကို flexible ထားလို့ရပါတယ်။ DynamoDB က auto-scaling ဖြစ်ပြီး, Lambda function ကနေ millisecond-level latency နဲ့ access လို့ရပါတယ် — serverless application (Lambda + API Gateway + DynamoDB) ရဲ့ database layer အဖြစ် အသုံးအများဆုံးပါ.

လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်

'Users' DynamoDB table ကို `userId` (Partition Key) နဲ့ create လုပ်ပြီး, user တစ်ယောက်ချင်းစီရဲ့ attribute (name, email, ဒါမှမဟုတ် custom field) ကို flexible ထည့်နိုင်ပါတယ် — Lambda function (Advanced lesson 2) က DynamoDB SDK ကို သုံးပြီး `PutItem`/`GetItem` operation တွေကို millisecond-level latency နဲ့ လုပ်နိုင်ပါတယ်.

အတူတူ ကြည့်မယ်

bash
# Create a DynamoDB table with userId as the partition key
aws dynamodb create-table \
  --table-name Users \
  --attribute-definitions AttributeName=userId,AttributeType=S \
  --key-schema AttributeName=userId,KeyType=HASH \
  --billing-mode PAY_PER_REQUEST

# Insert an item
aws dynamodb put-item \
  --table-name Users \
  --item '{"userId": {"S": "user-1"}, "name": {"S": "Aye Aye"}}'
You should see
$ aws dynamodb get-item --table-name Users --key '{"userId": {"S": "user-1"}}'
{"Item": {"userId": {"S": "user-1"}, "name": {"S": "Aye Aye"}}}

၅ မိနစ် စမ်းကြည့်

'Users' DynamoDB table တစ်ခု create လုပ်ကြည့်ပြီး, item ၂-၃ ခု put/get ကြည့်ပါ — RDS lesson (Intermediate) နဲ့ ဘယ်လို concept ကွာခြားလဲ ၂ ကြောင်း ရေးကြည့်ပါ။

သတိလေးတစ်ချက်

DynamoDB table ကို design လုပ်တဲ့အခါ access pattern (ဘယ်လို query တွေ လုပ်မလဲ) ကို အရင်ဆုံးဆုံးဖြတ်ပြီးမှ Primary Key ကို ရွေးချယ်ရပါတယ် — RDS လို 'ပြီးမှ index ထပ်ထည့်' ဆိုတာ NoSQL မှာ လွယ်ကူချေ နည်းပါတယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • Partition Key ကို well-distributed value (userId, orderId) မဟုတ်ဘဲ, low-cardinality value (status: 'active'/'inactive') ရွေးချယ်ခြင်း — traffic တွေ partition အနည်းငယ်ပေါ်ပဲ ကျစုစေပြီး performance ကျဆင်းနိုင်ပါတယ်
  • DynamoDB ကို complex relational query (multi-table JOIN) လိုအပ်တဲ့ use case အတွက် သုံးခြင်း — NoSQL ရဲ့ query pattern က RDS/SQL နဲ့ မတူပါ

အခု ကိုယ်တိုင် စမ်းကြည့်

'Users' DynamoDB table တစ်ခု create လုပ်ကြည့်ပြီး, item ၂-၃ ခု put/get ကြည့်ပါ — RDS lesson (Intermediate) နဲ့ ဘယ်လို concept ကွာခြားလဲ ၂ ကြောင်း ရေးကြည့်ပါ။

You'll know it worked when: $ aws dynamodb get-item --table-name Users --key '{"userId": {"S": "user-1"}}' {"Item": {"userId": {"S": "user-1"}, "name": {"S": "Aye Aye"}}}

DynamoDB Basics | Thuta Learning