ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
EC2-based architecture (Project 1) က server ကို run ထားရမှာမို့ idle ချိန်တောင် cost ဖြစ်ပါတယ် — Serverless architecture (Lambda + API Gateway + DynamoDB) ကတော့ request လာမှသာ run ပြီး, idle ချိန် cost လုံးဝ မရှိပါ (traffic နည်းတဲ့ side project/MVP အတွက် အထူး cost-effective ပါ)။ API Gateway က HTTP route ကို လက်ခံပြီး Lambda function ကို trigger, Lambda function က DynamoDB ကို IAM Role (access key မလို) နဲ့ ချိတ်ဆက်ပြီး data ကို read/write လုပ်ပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
`POST /todos` (todo item အသစ် create), `GET /todos/{id}` (todo item ဖတ်ခြင်း) endpoint ၂ ခုကို API Gateway ထဲမှာ define လုပ်ပြီး, Lambda function ၂ ခု (create-todo, get-todo) ကို ချိတ်ဆက်ပါ — Lambda တစ်ခုစီကို IAM Role (DynamoDB read/write permission ပါ) attach ထားပါ, DynamoDB table ကို `todoId` Partition Key နဲ့ create ထားပါ.
အတူတူ ကြည့်မယ်
# create_todo.py (Lambda function)
import json, boto3, uuid
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('Todos')
def lambda_handler(event, context):
body = json.loads(event['body'])
todo_id = str(uuid.uuid4())
table.put_item(Item={'todoId': todo_id, 'title': body['title'], 'done': False})
return {'statusCode': 201, 'body': json.dumps({'todoId': todo_id})}$ curl -X POST https://abc123.execute-api.us-east-1.amazonaws.com/todos -d '{"title":"Learn AWS"}'
{"todoId": "a1b2c3d4-..."}၅ မိနစ် စမ်းကြည့်
Todo app API (create + get endpoint, DynamoDB table) ကို ကိုယ်တိုင် တည်ဆောက်ကြည့်ပါ — `curl` ကနေ POST/GET request ပို့ပြီး end-to-end အလုပ်လုပ်ကြောင်း confirm လုပ်ကြည့်ပါ။
သတိလေးတစ်ချက်
Serverless architecture ကတော့ cost-effective ပါပေမယ့် 'ဘယ်တော့မှ cost မတက်ဘူး' လို့ မထင်ပါနှင့် — traffic တက်လာရင် (viral post) Lambda invocation count/DynamoDB read-write unit ကလည်း အလိုက်သင့် တက်လာနိုင်ပါတယ် — Cost Management chapter ရဲ့ Billing Alert ကို ဆက်လက် setup ထားပါ။