ခဏလေး ဒီလိုပဲ စဉ်းစားကြည့်
Lambda function တစ်ခုတည်းက HTTP request ကို တိုက်ရိုက် လက်ခံလို့ မရပါဘူး — API Gateway ကနေတစ်ဆင့် HTTP endpoint (URL) ကို Lambda function နဲ့ ချိတ်ဆက်ပေးရပါတယ်။ API Gateway က route (`/users`, `/products/{id}`) တစ်ခုချင်းစီကို HTTP method (GET, POST, PUT, DELETE) အလိုက် ခွဲခြားပြီး, ကိုက်ညီတဲ့ Lambda function ကို trigger ပေးပါတယ်။ Authentication, rate limiting, request/response transformation, CORS setup — အားလုံးကို API Gateway level မှာ handle လုပ်နိုင်ပါတယ်.
လက်တွေ့ scenario နဲ့ ချိတ်ကြည့်မယ်
`GET /users/{id}` ဆိုတဲ့ endpoint ကို API Gateway ထဲမှာ define လုပ်ပြီး, `get-user-function` Lambda ကို ချိတ်ဆက်ထားရင် — client က `https://api.example.com/users/123` ကို request ပို့တာနဲ့ API Gateway က `get-user-function` ကို `{id: 123}` parameter နဲ့ trigger ပေးပြီး, function ရဲ့ response ကို client ဆီ ပြန်ပို့ပေးပါတယ် — EC2/backend server run ထားစရာ လုံးဝ မလိုတဲ့ full REST API ဖြစ်သွားပါတယ်.
အတူတူ ကြည့်မယ်
# Create an HTTP API and connect it to a Lambda function
aws apigatewayv2 create-api \
--name tutorial-api \
--protocol-type HTTP \
--target arn:aws:lambda:us-east-1:123456789012:function:get-user-function
# The API is now live at a URL like:
# https://abc123.execute-api.us-east-1.amazonaws.com/$ curl https://abc123.execute-api.us-east-1.amazonaws.com/users/123
{"id": 123, "name": "Example User"}၅ မိနစ် စမ်းကြည့်
Lambda function (Advanced lesson 2) ကို API Gateway HTTP endpoint နဲ့ ချိတ်ဆက်ကြည့်ပါ — `curl` ဒါမှမဟုတ် browser ကနေ endpoint URL ကို request ပို့ပြီး response ရမလား စမ်းကြည့်ပါ။
သတိလေးတစ်ချက်
API Gateway ကို production မှာ authentication (API Key, IAM, JWT authorizer) မထားဘဲ public open ချထားရင် — attacker တွေက Lambda function ကို repeatedly invoke လုပ်ပြီး cost ကို တမင်တကာ တက်စေနိုင်ပါတယ်.