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

API Gateway

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

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

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

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

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 ဖြစ်သွားပါတယ်.

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

bash
# 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/
You should see
$ 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 ကို တမင်တကာ တက်စေနိုင်ပါတယ်.

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

  • API Gateway endpoint ကို authentication/rate limiting ဘာမှ ထားမထားဘဲ public ချထားခြင်း — abuse/DDoS risk ရှိပါတယ်
  • CORS configuration ကို မလုပ်ဘဲ browser ကနေ frontend app ကို API ချိတ်ဆက်ကြည့်ခြင်း — browser က CORS error ပြပါလိမ့်မယ်

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

Lambda function (Advanced lesson 2) ကို API Gateway HTTP endpoint နဲ့ ချိတ်ဆက်ကြည့်ပါ — `curl` ဒါမှမဟုတ် browser ကနေ endpoint URL ကို request ပို့ပြီး response ရမလား စမ်းကြည့်ပါ။

You'll know it worked when: $ curl https://abc123.execute-api.us-east-1.amazonaws.com/users/123 {"id": 123, "name": "Example User"}

API Gateway | Thuta Learning