Thuta Learning
AWS Advanced
ExercisesDevOpsအဆင့်မြင့်

Exercises: Architecture Review နဲ့ Troubleshooting Scenario ၆ ခု

AWS Advancedသင်ခန်းစာ 3260 မိနစ်

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

  • Incident တစ်ခုကို symptom ကနေ prevention အထိ အဆင့် ၅ ဆင့် method နဲ့ စနစ်တကျ ခွဲခြမ်းစိတ်ဖြာနိုင်မယ်
  • Symptom အမျိုးအစားအလိုက် ပထမဆုံး ကြည့်ရမယ့် evidence source (metric, log, CloudTrail, Cost Explorer) ကို ရွေးနိုင်မယ်
  • AWS CLI command နဲ့ Logs Insights query တွေနဲ့ root cause ကို အထောက်အထားနဲ့ ပြနိုင်မယ်
  • Fix တစ်ခုစီကို နောက်တစ်ခါ မဖြစ်အောင် guardrail (သို့) alarm အဖြစ် ပြောင်းနိုင်မယ်

ရိုးရိုးလေး ရှင်းပြမယ်

ဆရာဝန်တစ်ယောက်လို စဉ်းစားပါ

ဆရာဝန်ကောင်းတစ်ယောက်က 'ခေါင်းကိုက်တယ်' ဆိုတာနဲ့ ဆေးချက်ချင်း မပေးပါဘူး။ ဘယ်တုန်းက စလဲ၊ ဘယ်နားကိုက်လဲ မေးတယ်၊ သွေးစစ်တယ်၊ ပြီးမှ ရောဂါကို ဆုံးဖြတ်ပြီး ကုတယ်။ နောက်ဆုံး ထပ်မဖြစ်အောင် အကြံပေးတယ် (ကာကွယ်ဆေး)။

Cloud incident တွေကိုလည်း ဒီအတိုင်းပါပဲ - symptom ကို တိတိကျကျ ဖော်ပြ၊ evidence စု၊ root cause ကို ရှာ၊ ကု၊ ပြီးတော့ ထပ်မဖြစ်အောင် guardrail ထည့်တာပါ။ ဒီ lesson မှာ အရင် lesson တွေက service တွေအားလုံးကို ပေါင်းသုံးပြီး တကယ့် scenario ၆ ခုကို လေ့ကျင့်ပါမယ်။

Problem → Why → Solution

Symptom ကို ကုပြီး ရောဂါကို ချန်ထားခြင်း

Incident အချိန်မှာ ဖိအားများလို့ team တွေက ပထမဆုံး တွေးမိတဲ့ fix ကို ချက်ချင်း လုပ်တတ်ကြပါတယ်။ Lambda throttle ဖြစ်ရင် quota တိုးတောင်းတယ်၊ DynamoDB throttle ဖြစ်ရင် capacity တိုးတယ်၊ AccessDenied ဆိုရင် policy ထဲ '*' ထည့်လိုက်တယ်။ Alarm က ပြန်ငြိမ်သွားပြီး ticket ပိတ်လိုက်ပေမယ့် ရောဂါ အစစ်က ကျန်နေပါတယ်။

နောက်တစ်လ traffic ပိုများတဲ့နေ့မှာ ပြဿနာ ပိုကြီးကြီး ပြန်လာတယ်၊ ဒါမှမဟုတ် '*' ကြောင့် security hole အသစ် ပေါ်လာတယ်။ ပြီးတော့ စနစ်တကျ evidence မစုခဲ့လို့ ဘာပြောင်းခဲ့လဲ ဘယ်သူမှ မမှတ်မိတော့ပါဘူး။

  • Limit တိုးတာက ပြဿနာကို နောက်ဆုတ်ပေးရုံ ဖြစ်တတ်ပါတယ်
  • Permission ကျယ်တာက incident တစ်ခုကို နောက်တစ်ခုနဲ့ လဲလိုက်တာပါ
  • Evidence မရှိရင် postmortem က ခန့်မှန်းချက်တွေပဲ ဖြစ်ပါတယ်

ဘာကြောင့် ဒီလိုဖြစ်လဲ

Incident အတွင်း ရည်မှန်းချက်က 'ပြန်အလုပ်လုပ်အောင်' (containment) ပါ၊ ဒါက မှန်ပါတယ်။ ပြဿနာက containment ပြီးတာနဲ့ ရပ်လိုက်တာပါ။ Method တစ်ခု ရှိထားရင် containment ပြီးနောက် root cause နဲ့ prevention ကို အမြဲ ဆက်လုပ်ဖြစ်ပါတယ်။

အဆင့် ၅ ဆင့် review method

Symptom ကို တိုင်းတာလို့ရတဲ့ စကားနဲ့ ရေးပါ - 'နှေးတယ်' မဟုတ်ဘဲ 'checkout API p99 latency က 09:40 UTC ကစပြီး 300ms ကနေ 4s ဖြစ်တယ်၊ mobile user တွေပဲ ထိတယ်' ပါ။ ဘာ၊ ဘယ်တုန်းက၊ ဘယ်သူ ထိလဲ ဆိုတာ ရှင်းရင် evidence ရှာရမယ့် နေရာ ကျဉ်းသွားပါတယ်။

Evidence ကို အလွှာလိုက် စုပါ။ Metric က 'ဘာဖြစ်လဲ' နဲ့ 'ဘယ်တုန်းကလဲ' ကို ပြတယ်၊ log က 'ဘာကြောင့်' ကို ပြတယ်၊ CloudTrail က 'ဘယ်သူ ဘာပြောင်းခဲ့လဲ' ကို ပြပါတယ်။ Incident အများစုဟာ deploy (သို့) config change တစ်ခုနဲ့ အချိန်ကိုက်ပါတယ် - ဒါကြောင့် symptom စတဲ့အချိန်နားက CloudTrail event တွေကို အမြဲ ကြည့်ပါ။

Root cause က trigger နဲ့ မတူပါဘူး။ Traffic spike က trigger ပါ၊ 'partition key ကို date နဲ့ ရွေးခဲ့တာ' က root cause ပါ။ 'ဘာကြောင့်လဲ' ကို design ဆုံးဖြတ်ချက်တစ်ခု (သို့) guardrail ပျောက်နေတာ တစ်ခုကို တွေ့တဲ့အထိ ဆက်မေးပါ။

Fix ကို အဆင့်နှစ်ဆင့် ခွဲပါ - ပထမ containment (bleeding ကို ရပ်)၊ ပြီးမှ repair (ရောဂါကို ကု)။ နောက်ဆုံး prevention က ဒီ incident ကို နောက်တစ်ခါ အလိုအလျောက် ဖမ်းမယ့် (သို့) တားမယ့် alarm, SCP, test, baseline control တစ်ခု ဖြစ်ရပါမယ်။ 'သတိထားပါမယ်' ဆိုတာ prevention မဟုတ်ပါဘူး။

text
REVIEW LOOP
-----------
+-----------+   +------------+   +------------+   +---------+
| SYMPTOM   |-->| EVIDENCE   |-->| ROOT CAUSE |-->|   FIX   |
| what      |   | metrics    |   | ask 'why?' |   | contain |
| since when|   | logs       |   | until you  |   | then    |
| who       |   | CloudTrail |   | hit design |   | repair  |
+-----------+   +------------+   +------------+   +----+----+
      ^                                                 |
      |          +------------------------------+       |
      +----------| PREVENTION: alarm, SCP, test |<------+
                 | baseline control, runbook    |
                 +------------------------------+
Symptom အမျိုးအစားပထမဆုံး ကြည့်ရမယ့်နေရာ
Bill တက်တာCost Explorer (usage type အလိုက်)
Error / throttleCloudWatch metric (Throttles, 5xx, ThrottleEvents)
AccessDeniedError message အပြည့် + CloudTrail + policy တွေ
Data မှားတာ / နှစ်ခါဖြစ်တာLogs Insights (ID တစ်ခုချင်း ရေတွက်)
Exposure (public)IAM Access Analyzer + S3 policy status

Method က ကြီးကျယ်တဲ့ process တစ်ခု မဟုတ်ပါဘူး။ ငါးမိနစ်ကြာ အသေးစား ပြဿနာအတွက် မှတ်စု ငါးကြောင်းနဲ့ လုံလောက်ပြီး ကြီးမားတဲ့ outage အတွက်တော့ မှတ်တမ်းအပြည့် လိုပါတယ်။ အရေးကြီးတာက အဆင့်တွေကို ကျော်မသွားဖို့ပါ - အထူးသဖြင့် containment ပြီးတာနဲ့ 'အလုပ်ပြန်လုပ်ပြီ' ဆိုပြီး root cause နဲ့ prevention ကို ချန်ထားခဲ့တာမျိုး မဖြစ်စေဖို့ပါ။ အောက်က scenario တိုင်းကို ဒီအဆင့်တွေအတိုင်း ဖွဲ့စည်းထားပါတယ်။

Incident တိုင်းအတွက်
  1. Symptom: what, since when, who
  2. Evidence: metrics, logs, trail
  3. Root cause: ask why to design
  4. Fix: contain, then repair
  5. Prevent: alarm, SCP or test

Prevention မပါတဲ့ postmortem က မပြီးသေးတဲ့ postmortem ပါ။

Review နေ့အတွက် guardrail check script

Scenario တွေမစခင် ဒီ lesson ရဲ့ incident အများစုကို ဖြစ်စေတဲ့ misconfiguration တွေကို ကြိုရှာပေးတဲ့ script လေးတစ်ခု ရေးကြည့်ရအောင်။ Bucket-level Block Public Access၊ DLQ မပါတဲ့ queue၊ consumer timeout ထက် တိုတဲ့ visibility timeout နဲ့ PITR မဖွင့်ထားတဲ့ table တွေကို စစ်ပါတယ်။ Read-only ဖြစ်လို့ production account မှာ run လို့ လုံခြုံပါတယ်။

guardrail_check.py
"""Review-day guardrail check: the misconfigurations behind this lesson's incidents."""
from __future__ import annotations

import json

import boto3
from botocore.exceptions import ClientError

s3 = boto3.client("s3")
sqs = boto3.client("sqs")
ddb = boto3.client("dynamodb")
CONSUMER_TIMEOUT = 30  # seconds: the Lambda timeout of the queue consumers
findings: list[str] = []


def report(level: str, resource: str, message: str) -> None:
    print(f"[{level:<4}] {resource}: {message}")
    if level != "ok":
        findings.append(resource)


def check_buckets() -> None:
    for bucket in sorted(b["Name"] for b in s3.list_buckets()["Buckets"]):
        try:
            cfg = s3.get_public_access_block(Bucket=bucket)
            flags = cfg["PublicAccessBlockConfiguration"]
            if all(flags.values()):
                report("ok", f"s3:{bucket}", "Block Public Access fully on")
            else:
                off = sorted(k for k, v in flags.items() if not v)
                report("FAIL", f"s3:{bucket}", "BPA partly off: " + ", ".join(off))
        except ClientError as err:
            if err.response["Error"]["Code"] != "NoSuchPublicAccessBlockConfiguration":
                raise
            report("FAIL", f"s3:{bucket}", "no bucket-level Block Public Access")


def check_queues() -> None:
    urls = sorted(sqs.list_queues().get("QueueUrls", []))
    for url in urls:
        name = url.rsplit("/", 1)[-1]
        if name.endswith("-dlq"):
            continue
        attrs = sqs.get_queue_attributes(
            QueueUrl=url, AttributeNames=["All"]
        )["Attributes"]
        if "RedrivePolicy" not in attrs:
            report("FAIL", f"sqs:{name}", "no DLQ - a poison message retries forever")
            continue
        redrive = json.loads(attrs["RedrivePolicy"])
        visibility = int(attrs["VisibilityTimeout"])
        report("ok", f"sqs:{name}", f"DLQ after {redrive['maxReceiveCount']} receives")
        if visibility < 6 * CONSUMER_TIMEOUT:
            report("WARN", f"sqs:{name}",
                   f"visibility {visibility}s < 6 x {CONSUMER_TIMEOUT}s consumer timeout")


def check_tables() -> None:
    for table in sorted(ddb.list_tables()["TableNames"]):
        backups = ddb.describe_continuous_backups(TableName=table)
        pitr = backups["ContinuousBackupsDescription"]["PointInTimeRecoveryDescription"]
        if pitr["PointInTimeRecoveryStatus"] == "ENABLED":
            report("ok", f"dynamodb:{table}", "point-in-time recovery on")
        else:
            report("WARN", f"dynamodb:{table}", "point-in-time recovery off")


if __name__ == "__main__":
    check_buckets()
    check_queues()
    check_tables()
    print(f"{len(findings)} finding(s): {', '.join(findings)}")

Browser ထဲမှာ run လို့ မရပါ

ဒီ code ဟာ AWS account အစစ်ပေါ်မှာ run ရမယ့် code ဖြစ်လို့ browser playground ထဲမှာ run လို့ မရပါ။ ကိုယ့် terminal (သို့) AWS CloudShell ထဲမှာ စမ်းပါ။

Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်

  1. report()print(f"[{level:<4}] {resource}: {message}")

    Result တိုင်းကို level (ok/WARN/FAIL)၊ resource၊ message ပုံစံတစ်မျိုးတည်းနဲ့ print လုပ်တော့ grep နဲ့ စစ်ရလွယ်ပြီး CI ထဲမှာလည်း parse လုပ်လို့ရပါတယ်။ ok မဟုတ်တာတွေကို findings list ထဲ စုပါတယ်။

  2. check_bucketsexcept ClientError ... NoSuchPublicAccessBlockConfiguration

    Bucket မှာ Block Public Access configuration လုံးဝ မရှိရင် API က error ပြန်ပါတယ်။ အဲဒါကို 'BPA မရှိ' finding အဖြစ် ပြောင်းပြီး တခြား error တွေကိုတော့ ပြန်ပစ်ပါတယ် - permission မရှိတာကို 'အဆင်ပြေတယ်' လို့ မှားမယူမိအောင်ပါ။ Flag လေးခုထဲက ပိတ်ထားတာတွေကိုလည်း နာမည်နဲ့ ပြပါတယ်။

  3. check_queuesif visibility < 6 * CONSUMER_TIMEOUT:

    RedrivePolicy မရှိရင် poison message က အဆုံးမရှိ retry ဖြစ်ပါတယ်။ Visibility timeout က consumer Lambda timeout ရဲ့ ၆ ဆ မပြည့်ရင် message နှစ်ခါ process ဖြစ်နိုင်လို့ WARN ပေးပါတယ် - scenario 5 ရဲ့ root cause ပါပဲ။

  4. check_tablesdescribe_continuous_backups(TableName=table)

    PITR ပိတ်ထားတဲ့ table က မှားဖျက်မိရင် (သို့) bug က data ဖျက်မိရင် အချိန်တစ်ခုဆီ ပြန်ယူလို့ မရပါဘူး။ Cost ရှိလို့ FAIL မဟုတ်ဘဲ WARN ထားပြီး team က ဆုံးဖြတ်ပါစေ။

You should see
[ok  ] s3:app-assets: Block Public Access fully on
[FAIL] s3:legacy-reports: no bucket-level Block Public Access
[FAIL] s3:partner-exports: BPA partly off: BlockPublicPolicy, RestrictPublicBuckets
[FAIL] sqs:emails: no DLQ - a poison message retries forever
[ok  ] sqs:orders: DLQ after 5 receives
[WARN] sqs:orders: visibility 30s < 6 x 30s consumer timeout
[ok  ] dynamodb:orders: point-in-time recovery on
[WARN] dynamodb:sessions: point-in-time recovery off
5 finding(s): s3:legacy-reports, s3:partner-exports, sqs:emails, sqs:orders, dynamodb:sessions

Scenario 1: NAT Gateway bill ရုတ်တရက် တက်လာခြင်း

Symptom: လစဉ် bill က ၄၀% တက်လာပြီး Cost Explorer မှာ 'EC2 - Other' က အများဆုံး တိုးနေတယ်။ App traffic က မပြောင်းပါဘူး။ ၂ ပတ်က data pipeline team က S3 ကနေ နေ့စဉ် TB ချီ ဖတ်တဲ့ batch job အသစ်ကို private subnet ထဲ တင်ခဲ့ပါတယ်။

Usage type အလိုက် ခွဲကြည့်ပါ

'EC2 - Other' ထဲမှာ EBS, data transfer, NAT Gateway စတာတွေ ပေါင်းထားလို့ usage type group နဲ့ filter လုပ်ပါ။ NAT Gateway - Data Processed က တိုးနေရင် bytes ပမာဏ ပြဿနာပါ။

ဘယ် NAT, ဘယ်လောက်လဲ

AWS/NATGateway namespace ထဲက BytesOutToDestination ကို နေ့အလိုက် ကြည့်ပြီး တိုးလာတဲ့နေ့ကို batch job စတဲ့နေ့နဲ့ တိုက်ကြည့်ပါ။

Bytes ဘယ်ကို သွားလဲ

NAT ENI ရဲ့ flow log တွေကို Logs Insights နဲ့ source/destination အလိုက် စုပါ။ Destination IP တွေက S3 ရဲ့ public IP range ထဲ ကျနေရင် S3 traffic က NAT ကို ဖြတ်နေတာ သေချာပါပြီ။

nat-investigation.sh
# 1. Which usage type grew? (NAT shows up under "EC2 - Other")
aws ce get-cost-and-usage \
  --time-period Start=2026-10-01,End=2026-11-01 \
  --granularity DAILY --metrics UnblendedCost \
  --filter file://nat-filter.json
# nat-filter.json:
# {"Dimensions": {"Key": "USAGE_TYPE_GROUP",
#                 "Values": ["EC2: NAT Gateway - Data Processed"]}}

# 2. Which NAT gateway, and how many bytes?
aws cloudwatch get-metric-statistics --namespace AWS/NATGateway \
  --metric-name BytesOutToDestination \
  --dimensions Name=NatGatewayId,Value=nat-0a1b2c3d4e5f67890 \
  --start-time 2026-10-25T00:00:00Z --end-time 2026-11-01T00:00:00Z \
  --period 86400 --statistics Sum

# 3. Does the VPC already have an S3 gateway endpoint?
aws ec2 describe-vpc-endpoints \
  --filters Name=vpc-id,Values=vpc-0a1b2c3d4e5f67890 \
  --query 'VpcEndpoints[].[ServiceName,VpcEndpointType]'
nat-top-talkers.logsinsights
# CloudWatch Logs Insights, on the VPC Flow Logs log group.
# Flow records of the NAT gateway's network interface: who sends the bytes,
# and where to? (10.20.0.0/16 is the VPC CIDR)
filter interfaceId = "eni-0a1b2c3d4e5f67890"
| filter isIpv4InSubnet(srcAddr, "10.20.0.0/16")
| filter not isIpv4InSubnet(dstAddr, "10.20.0.0/16")
| stats sum(bytes) as totalBytes by srcAddr, dstAddr
| sort totalBytes desc
| limit 10

Root cause → fix → prevention

Root cause: VPC မှာ S3 gateway endpoint မရှိလို့ same-region S3 traffic အားလုံး NAT ကို ဖြတ်ပြီး GB တိုင်း process ကြေး ပေးနေရတာပါ။ Fix: S3 (နဲ့ DynamoDB) gateway endpoint ထည့်ပြီး private route table တွေနဲ့ ချိတ်ပါ - gateway endpoint က အခမဲ့ပါ။ ECR image pull များရင် ECR interface endpoint တွေကိုလည်း စဉ်းစားပါ။ Prevention: gateway endpoint တွေကို baseline network stack ထဲ ထည့်ပြီး NAT usage type ပေါ်မှာ budget alert ထားပါ။

Scenario 2: Traffic spike အတွင်း Lambda throttle ဖြစ်ခြင်း

Symptom: Sale campaign စတဲ့ ၁၀ မိနစ်အတွင်း checkout API က 429 / 502 error တွေ ပြန်တယ်။ ထူးဆန်းတာက checkout function ရဲ့ traffic က မျှော်လင့်ထားတာထက် မများပါဘူး။ တစ်ချိန်တည်းမှာ marketing team က product ပုံ အသစ် ၂ သိန်းကို S3 ထဲ upload လုပ်ခဲ့ပြီး image-resizer function ကို trigger ဖြစ်စေခဲ့ပါတယ်။

Account limit ကို စစ်ပါ

Lambda concurrency က region တစ်ခုမှာ account ရှိ function အားလုံး မျှသုံးရတဲ့ pool တစ်ခုပါ (default quota က 1,000 ဖြစ်ပြီး တိုးတောင်းလို့ရပါတယ်)။ get-account-settings က limit နဲ့ unreserved ပမာဏကို ပြပါတယ်။

ဘယ်သူ throttle ခံရလဲ၊ ဘယ်သူ စားနေလဲ

checkout-api ရဲ့ Throttles metric နဲ့ image-resizer ရဲ့ ConcurrentExecutions ကို အချိန်တူ ကြည့်ပါ။ Resizer က pool ကို အပြည့်နီးပါး ယူထားတာ တွေ့ရပါမယ်။

lambda-throttling.sh
# Account-wide concurrency limit and what is left unreserved
aws lambda get-account-settings \
  --query 'AccountLimit.[ConcurrentExecutions,UnreservedConcurrentExecutions]'

# Who was throttled, and who was eating the concurrency?
aws cloudwatch get-metric-statistics --namespace AWS/Lambda \
  --metric-name Throttles --dimensions Name=FunctionName,Value=checkout-api \
  --start-time 2026-11-07T09:00:00Z --end-time 2026-11-07T11:00:00Z \
  --period 60 --statistics Sum
aws cloudwatch get-metric-statistics --namespace AWS/Lambda \
  --metric-name ConcurrentExecutions \
  --dimensions Name=FunctionName,Value=image-resizer \
  --start-time 2026-11-07T09:00:00Z --end-time 2026-11-07T11:00:00Z \
  --period 60 --statistics Maximum

# Fix: guarantee the critical path, cap the noisy batch job
aws lambda put-function-concurrency --function-name checkout-api \
  --reserved-concurrent-executions 200
aws lambda put-function-concurrency --function-name image-resizer \
  --reserved-concurrent-executions 50

Root cause → fix → prevention

Root cause: critical function နဲ့ batch function က concurrency pool တစ်ခုတည်းကို အကာအကွယ်မရှိဘဲ မျှသုံးနေတာပါ။ Fix: checkout-api ကို reserved concurrency ပေးပြီး (အာမခံ + အများဆုံး ကန့်သတ်ချက်) image-resizer ကို reserved concurrency သေးသေးနဲ့ ကန့်သတ်ပါ။ Resizer ကို S3 ကနေ တိုက်ရိုက်မဟုတ်ဘဲ SQS နောက်မှာ ထားပြီး maxConcurrency နဲ့ ထိန်းရင် ပိုကောင်းပါတယ်။ Prevention: account ConcurrentExecutions ပေါ်မှာ alarm ထားပြီး function တိုင်းရဲ့ concurrency budget ကို design review မှာ ဆုံးဖြတ်ပါ။

Scenario 3: Cross-account AccessDenied

Symptom: Shared services account (111122223333) ထဲက reporting job က တနင်္လာနေ့ မနက်ကစပြီး reporting account (444455556666) ထဲက role ကို assume လုပ်လို့ မရတော့ပါဘူး - 'not authorized to perform: sts:AssumeRole'။ Code မပြောင်းပါဘူး။ သောကြာနေ့က platform team က reporting-job role ကို CDK နဲ့ ဖျက်ပြီး ပြန်ဖန်တီးခဲ့ပါတယ်။

စစ်ရမယ့်အလွှာဘယ်လို စစ်မလဲ
Caller identityget-caller-identity - မျှော်လင့်တဲ့ role ဟုတ်ရဲ့လား
Caller ရဲ့ identity policysts:AssumeRole ကို target role ARN အတွက် allow လား
Target role ရဲ့ trust policyPrincipal က caller ကို ညွှန်လား၊ condition တွေ ကိုက်လား
SCP (account နှစ်ခုလုံး)Region, action, principal ကို deny လုပ်ထားလား
cross-account-debug.sh
# Who am I really? (a surprising number of tickets end here)
aws sts get-caller-identity

# Reproduce the exact call the job makes, and read the full message
aws sts assume-role \
  --role-arn arn:aws:iam::444455556666:role/reporting-reader \
  --role-session-name debug-ticket-4711

# Does the target role trust us? (run in the TARGET account)
aws iam get-role --role-name reporting-reader \
  --query 'Role.AssumeRolePolicyDocument'

# Which SCPs apply to the target account? (run in the management account)
aws organizations list-policies-for-target --target-id 444455556666 \
  --filter SERVICE_CONTROL_POLICY
aws organizations describe-policy --policy-id p-a1b2c3d4 \
  --query 'Policy.Content' --output text

# What did CloudTrail record for the failed calls?
aws cloudtrail lookup-events \
  --lookup-attributes AttributeKey=EventName,AttributeValue=AssumeRole \
  --max-results 20 --query 'Events[].CloudTrailEvent'

Trust policy ကို ဖတ်ကြည့်တော့ Principal နေရာမှာ role ARN မဟုတ်ဘဲ 'AROA...' နဲ့ စတဲ့ unique ID တစ်ခု ပေါ်နေပါတယ်။ IAM က trust policy ထဲက role ARN ကို သိမ်းတဲ့အခါ role ရဲ့ unique ID နဲ့ ချိတ်ထားတာမို့ role ကို ဖျက်လိုက်တာနဲ့ အဲဒီ principal က ID ဟောင်းအဖြစ် ကျန်ခဲ့ပါတယ်။ နာမည်တူ role အသစ်က ID အသစ်ရလို့ trust မရတော့ပါဘူး။ ဒါက security feature ပါ - နာမည်တူ role ပြန်ဖန်တီးရုံနဲ့ access ပြန်မရအောင်ပါ။

reporting-reader-trust.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "TrustOnlyTheReportingJobRole",
      "Effect": "Allow",
      "Principal": { "AWS": "arn:aws:iam::111122223333:role/reporting-job" },
      "Action": "sts:AssumeRole",
      "Condition": {
        "StringEquals": { "aws:PrincipalOrgID": "o-a1b2c3d4e5" }
      }
    }
  ]
}

Fix → prevention (နဲ့ SCP ကိစ္စ)

Fix: trust policy ကို role ARN နဲ့ ပြန် update လုပ်ပါ (အပေါ်က JSON)၊ aws:PrincipalOrgID condition က organization ပြင်ပကနေ မရအောင် ထပ်ကာကွယ်ပါတယ်။ Prevention: cross-account role တွေကို RETAIN ထားပြီး replace ဖြစ်စေမယ့် CDK change (role name ပြောင်းတာ) ကို diff မှာ ဖမ်းပါ၊ AssumeRole fail ပေါ်မှာ alarm ထားပါ။ Error message က 'explicit deny in a service control policy' လို policy type ကို ဖော်ပြနေရင်တော့ trust policy မဟုတ်ဘဲ SCP ကို ကြည့်ပါ - AccessDenied message အများစုက ဘယ် policy type က deny လုပ်လဲ ဖော်ပြလာပါပြီ။

Scenario 4: DynamoDB hot partition throttling

Symptom: orders table က on-demand mode ဖြစ်ပေမယ့် flash sale အတွင်း WriteThrottleEvents တွေ ပေါ်လာတယ်။ Table တစ်ခုလုံးရဲ့ consumed capacity က table limit နဲ့ အဝေးကြီး လိုသေးပါတယ်။ Partition key က 'STATUS#PENDING' လို status value ပါ - order အသစ်တိုင်း PENDING နဲ့ စပါတယ်။

Table လား key လား ခွဲပါ

Table-wide consumed capacity နိမ့်ပြီး throttle ရှိနေရင် partition တစ်ခု (key တစ်ခု) ပေါ် ဝန်စုနေတာပါ။ Partition တစ်ခုမှာ တစ်စက္ကန့် 3,000 RCU နဲ့ 1,000 WCU ကန့်သတ်ချက် ရှိပြီး on-demand ဖြစ်လည်း ဒီ limit က ရှိနေဆဲပါ။

Hot key ကို နာမည်နဲ့ ရှာပါ

CloudWatch Contributor Insights for DynamoDB ကို ဖွင့်ရင် အများဆုံး access / throttle ခံရတဲ့ key တွေကို ranking နဲ့ ပြပါတယ်။ STATUS#PENDING က ထိပ်ဆုံးမှာ ရှိနေပါမယ်။

ddb-hot-key.sh
# Throttles on the table vs. consumed capacity: is it the TABLE or a KEY?
aws cloudwatch get-metric-statistics --namespace AWS/DynamoDB \
  --metric-name WriteThrottleEvents --dimensions Name=TableName,Value=orders \
  --start-time 2026-11-07T09:00:00Z --end-time 2026-11-07T10:00:00Z \
  --period 60 --statistics Sum

# Turn on Contributor Insights: it ranks the most-accessed / most-throttled keys
aws dynamodb update-contributor-insights --table-name orders \
  --contributor-insights-action ENABLE
aws dynamodb describe-contributor-insights --table-name orders

Root cause → fix → prevention

Root cause: cardinality နိမ့်တဲ့ attribute (status) ကို partition key အဖြစ် ရွေးခဲ့တဲ့ data model ဆုံးဖြတ်ချက်ပါ - capacity ပြဿနာ မဟုတ်ပါဘူး။ Fix: base table ရဲ့ PK ကို ORDER#<id> လို cardinality မြင့်တဲ့ key ပြောင်းပြီး status နဲ့ query ဖို့ GSI လိုရင် 'STATUS#PENDING#<0-9>' လို suffix နဲ့ write sharding လုပ်ပါ (read လုပ်ရင် shard ၁၀ ခုလုံး query ရပါတယ်)။ GSI throttle ဖြစ်ရင် base table write ကိုပါ throttle လုပ်တာ သတိထားပါ။ Prevention: access pattern နဲ့ key cardinality ကို design review checklist ထဲ ထည့်ပြီး ThrottledRequests > 0 အပေါ် alarm ထားပါ။

Scenario 5: SQS message တွေ နှစ်ခါ process ဖြစ်ခြင်း

Symptom: Customer တချို့ order confirmation email နှစ်စောင် ရတယ်၊ တချို့ order တွေမှာ loyalty point နှစ်ခါ ထည့်ခံရတယ်။ ပြဿနာက traffic များတဲ့ ညနေပိုင်းမှာပဲ ဖြစ်ပါတယ်။ Worker က အလုပ်များရင် ၄၀-၅၀ စက္ကန့် ကြာပါတယ်။

Duplicate ကို သက်သေပြပါ

Logs Insights နဲ့ orderId တစ်ခုချင်း process ဖြစ်တဲ့ အကြိမ်ရေကို ရေတွက်ပါ။ နှစ်ခါဖြစ်တာတွေရဲ့ 'slowest' duration က 30 စက္ကန့်ကျော်နေတာ တွေ့ရပါမယ်။

နံပါတ်နှစ်ခုကို တိုက်ကြည့်ပါ

Queue ရဲ့ VisibilityTimeout (30) နဲ့ function ရဲ့ Timeout (60) ကို တိုက်ကြည့်ပါ။ Visibility timeout က function timeout ထက် တိုနေပါတယ်။

duplicates.logsinsights
# CloudWatch Logs Insights, on /aws/lambda/order-worker
# Orders that were processed more than once in the window
filter @message like /processed order/
| parse @message "processed order * in * ms" as orderId, ms
| stats count(*) as times, max(ms) as slowest by orderId
| filter times > 1
| sort times desc
| limit 20
sqs-visibility.sh
# Compare the two numbers that must agree
aws sqs get-queue-attributes --queue-url "$QUEUE_URL" \
  --attribute-names VisibilityTimeout RedrivePolicy
aws lambda get-function-configuration --function-name order-worker \
  --query 'Timeout'

# Fix: visibility timeout at least 6x the function timeout (60s -> 360s)
aws sqs set-queue-attributes --queue-url "$QUEUE_URL" \
  --attributes VisibilityTimeout=360

Root cause → fix → prevention

Root cause: batch က 30 စက္ကန့်ထက် ကြာရင် message တွေ queue မှာ ပြန်မြင်ရပြီး တခြား invocation က ယူသွားတာပါ။ Consumer ကလည်း idempotent မဖြစ်လို့ duplicate က effect နှစ်ခါ ဖြစ်စေပါတယ်။ Fix: visibility timeout ကို function timeout ရဲ့ ၆ ဆ (360s) ထားပြီး project-event-driven-orders lesson ထဲကလို conditional write နဲ့ idempotent ဖြစ်အောင် လုပ်ပါ၊ partial batch response ကိုလည်း ဖွင့်ပါ။ Prevention: ဒီ lesson ရဲ့ guardrail script ကို CI မှာ run ပြီး visibility/timeout မကိုက်တာကို deploy မတိုင်ခင် ဖမ်းပါ။

Scenario 6: S3 bucket မတော်တဆ public ဖြစ်သွားခြင်း

Symptom: IAM Access Analyzer က partner-exports bucket အတွက် 'public access' finding ပေးတယ်။ Partner တစ်ယောက် download လုပ်ရလွယ်အောင် engineer တစ်ယောက်က bucket ရဲ့ Block Public Access ကို တစ်စိတ်တစ်ပိုင်း ပိတ်ပြီး Principal '*' ပါတဲ့ bucket policy ထည့်ခဲ့ပါတယ်။ ၂၀၂၃ ဧပြီကစပြီး bucket အသစ်တွေမှာ BPA default ဖွင့်ထားပေမယ့် လက်နဲ့ ပိတ်လို့ ရနေဆဲပါ။

အရင် contain လုပ်ပါ

Bucket နဲ့ account အဆင့် နှစ်ခုလုံးမှာ BPA flag လေးခုလုံး ပြန်ဖွင့်ပါ။ BPA က policy ကို မဖျက်ဘဲ public effect ကို ချက်ချင်း ပိတ်ပေးလို့ evidence ကို ထိခိုက်မှု မရှိပါဘူး။

ထိခိုက်မှုကို တိုင်းတာပါ

Public ဖြစ်နေတဲ့ ကာလအတွင်း ဘယ်သူ ဘာ download လုပ်ခဲ့လဲ သိဖို့ S3 server access log (သို့) CloudTrail S3 data event လိုပါတယ် - incident မတိုင်ခင်ကတည်းက ဖွင့်ထားမှ ရပါတယ်။ မရှိရင် data ကို exposed လို့ ယူဆပြီး လုပ်ငန်းစဉ်အတိုင်း သက်ဆိုင်သူတွေကို အသိပေးရပါတယ်။

Partner ကို မှန်ကန်တဲ့ နည်းနဲ့ access ပေးပါ

Public bucket အစား presigned URL (သက်တမ်းတို)၊ partner account ကို cross-account bucket policy (သို့) CloudFront + OAC ကို သုံးပါ။

s3-exposure.sh
# Is the bucket public, and through which door: policy or ACL?
aws s3api get-bucket-policy-status --bucket partner-exports
aws s3api get-public-access-block --bucket partner-exports
aws s3api get-bucket-policy --bucket partner-exports --query Policy --output text

# Contain first: close the door at bucket AND account level
BPA="BlockPublicAcls=true,IgnorePublicAcls=true"
BPA="$BPA,BlockPublicPolicy=true,RestrictPublicBuckets=true"
aws s3api put-public-access-block --bucket partner-exports \
  --public-access-block-configuration "$BPA"
aws s3control put-public-access-block --account-id 111122223333 \
  --public-access-block-configuration "$BPA"

# Then measure the damage: who downloaded what (needs server access logs
# or CloudTrail S3 data events enabled BEFORE the incident)
aws accessanalyzer list-findings --analyzer-arn "$ANALYZER_ARN" \
  --filter '{"resourceType": {"eq": ["AWS::S3::Bucket"]}}'

Prevention အတွက် account-level BPA ကို ဘယ်သူမှ ပြန်မပိတ်နိုင်အောင် SCP တစ်ခု ထည့်ပါ။ Break-glass role တစ်ခုကိုပဲ ခြွင်းချက်ပေးထားပါတယ်။ Guardrail script ကလည်း bucket-level BPA ပိတ်ထားတာကို နေ့စဉ် ဖမ်းပေးပါမယ်။

scp-protect-account-bpa.json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "NobodyTurnsOffAccountLevelBPA",
      "Effect": "Deny",
      "Action": "s3:PutAccountPublicAccessBlock",
      "Resource": "*",
      "Condition": {
        "ArnNotLike": {
          "aws:PrincipalArn": "arn:aws:iam::*:role/platform-break-glass"
        }
      }
    }
  ]
}

Production မှာ

Production team တွေရဲ့ review ယဉ်ကျေးမှု

Team ကောင်းတွေက incident တိုင်းနောက်မှာ blameless postmortem ရေးပါတယ် - 'ဘယ်သူ မှားလဲ' မဟုတ်ဘဲ 'ဘယ် system ကြောင့် ဒီအမှားက လွယ်လွယ်ကူကူ ဖြစ်ခဲ့လဲ' ကို မေးပါတယ်။ Timeline ကို CloudTrail, deploy log, alarm history ကနေ မိနစ်အလိုက် ပြန်တည်ဆောက်ပြီး action item တိုင်းမှာ owner နဲ့ due date ပါပါတယ်။

Scenario တွေကို runbook အဖြစ် ပြောင်းထားပါတယ် - ဒီ lesson ထဲက command နဲ့ query တွေကို on-call engineer က ညသန်းခေါင်မှာ copy-paste လုပ်ပြီး သုံးလို့ရအောင်ပါ။ Game day တွေမှာ staging account ထဲ ဒီ failure တွေကို ရည်ရွယ်ချက်ရှိရှိ ဖန်တီးပြီး (AWS Fault Injection Service နဲ့ သို့မဟုတ် လက်နဲ့) runbook နဲ့ alarm တွေကို စမ်းပါတယ်။

New architecture တွေကိုလည်း launch မတိုင်ခင် AWS Well-Architected Framework ရဲ့ pillar တွေနဲ့ review လုပ်ပြီး 'ဒီ incident ၆ ခုထဲက ဘယ်ဟာ ဒီ design မှာ ဖြစ်နိုင်လဲ' လို့ မေးကြပါတယ်။ Launch မတိုင်ခင် ဒီမေးခွန်းကို ဖြေရင် တစ်နာရီပဲ ကုန်ပြီး outage အတွင်း ဖြေရရင်တော့ အဆများစွာ ပိုကုန်ပါတယ်။

အမှားများ

Troubleshooting မှာ အဖြစ်များတဲ့ အမှားများ

Evidence ကို ဖျက်ပစ်ခြင်း

ပြဿနာရှိတဲ့ instance ကို ချက်ချင်း terminate လုပ်တာ၊ log group retention ကို လျှော့တာ၊ public bucket policy ကို delete လုပ်ပြီး ဘာရှိခဲ့လဲ မမှတ်တာတွေက root cause ရှာဖို့ လိုတဲ့ အထောက်အထားကို ဖျက်ပစ်ပါတယ်။ Contain လုပ်တဲ့အခါ isolate (security group ပြောင်း၊ BPA ဖွင့်) လုပ်ပြီး snapshot နဲ့ copy တွေ အရင်ယူပါ။

တစ်ခါတည်း အများကြီး ပြောင်းခြင်း

Timeout တိုး၊ memory တိုး၊ concurrency ပြောင်း၊ code rollback - အားလုံး တစ်ပြိုင်နက် လုပ်လိုက်ရင် ပြဿနာ ပျောက်သွားပေမယ့် ဘယ်ဟာကြောင့်လဲ ဘယ်သူမှ မသိတော့ပါဘူး။ Containment အတွက် အန္တရာယ်အနည်းဆုံး change တစ်ခုကို အရင်လုပ်ပြီး ရလဒ်ကို metric နဲ့ စစ်ပါ။

Identity policy တစ်ခုတည်းကိုပဲ ကြည့်ခြင်း

AccessDenied မှာ identity policy က allow လုပ်ထားလို့ 'permission ရှိတယ်' လို့ ယူဆတတ်ပါတယ်။ တကယ်တော့ resource policy, trust policy, permission boundary, session policy နဲ့ SCP တွေ အားလုံးက ဆုံးဖြတ်ချက်မှာ ပါပြီး explicit deny တစ်ခုက allow အားလုံးကို အနိုင်ယူပါတယ်။

Best Practices

Best practices

  • Symptom ကို အချိန်၊ metric၊ ထိခိုက်သူ ပါအောင် တိတိကျကျ ရေးပါ
  • Symptom စတဲ့အချိန်နားက CloudTrail change တွေကို အမြဲ စစ်ပါ
  • Contain ကို repair နဲ့ ခွဲပြီး evidence ကို ထိန်းသိမ်းပါ
  • Postmortem တိုင်းမှာ automated prevention item အနည်းဆုံး တစ်ခု ပါရပါမယ်

💰 Cost & Cleanup

Guardrail script က read-only ဖြစ်လို့ resource ဘာမှ မဖန်တီးပါဘူး။ ဒါပေမယ့် investigation tool တွေမှာ ကုန်ကျစရိတ် ရှိပါတယ် - Cost Explorer API request တစ်ခုချင်း ကြေးရှိတယ်၊ DynamoDB Contributor Insights က analyse လုပ်တဲ့ event အလိုက်၊ VPC Flow Logs က CloudWatch Logs ingestion နဲ့ storage အလိုက်၊ CloudTrail S3 data event နဲ့ Logs Insights query က scan လုပ်တဲ့ data ပမာဏအလိုက် ငွေကုန်ပါတယ်။ လေ့ကျင့်ဖို့ ဖွင့်ခဲ့တဲ့ diagnostic တွေကို ပြီးရင် ပြန်ပိတ်ပါ။

စမ်းပြီးရင် ဖျက်ဖို့ command

cleanup.sh
# The audit script only reads. If you enabled diagnostics while practising,
# switch them off again: Contributor Insights is billed per event analysed.
aws dynamodb update-contributor-insights --table-name orders \
  --contributor-insights-action DISABLE
aws lambda delete-function-concurrency --function-name image-resizer

Mini challenge

Guardrail script ထဲ DLQ depth check ထည့်ပါ

Scenario တွေထဲက သင်ခန်းစာ တစ်ခုက 'ဘယ်သူမှ မကြည့်တဲ့ DLQ' ပါ။ '-dlq' နဲ့ ဆုံးတဲ့ queue တိုင်းမှာ message စောင့်နေလား စစ်တဲ့ function တစ်ခု ရေးပါ။

  • '-dlq' နဲ့ ဆုံးတဲ့ queue တွေကိုပဲ စစ်ရမယ်
  • ApproximateNumberOfMessages > 0 ဆိုရင် FAIL၊ မဟုတ်ရင် ok ကို အခြား check တွေနဲ့ ပုံစံတူ print လုပ်ရမယ်
  • Attention လိုတဲ့ queue name တွေကို list အဖြစ် return ပြန်ရမယ်

ရလဒ်: emails-dlq (ဗလာ) နဲ့ orders-dlq (message ၁ ခု) ရှိတဲ့ account မှာ '[ok ] sqs:emails-dlq: 0 message(s) waiting'၊ '[FAIL] sqs:orders-dlq: 1 message(s) waiting' နဲ့ "needs attention: ['orders-dlq']" ကို မြင်ရပါမယ်။

အရိပ်အမြွက် ကြည့်ရန်

get_queue_attributes မှာ AttributeNames=['ApproximateNumberOfMessages'] ပဲ တောင်းပါ။ တန်ဖိုးက string ဖြစ်လို့ int() ပြောင်းပါ။

အဖြေ ကြည့်ရန်
check_dlqs.py
import boto3

sqs = boto3.client("sqs")


def check_dead_letter_queues() -> list[str]:
    """A DLQ that is not empty is an incident nobody has looked at yet."""
    waiting = []
    for url in sorted(sqs.list_queues(QueueNamePrefix="").get("QueueUrls", [])):
        name = url.rsplit("/", 1)[-1]
        if not name.endswith("-dlq"):
            continue
        attrs = sqs.get_queue_attributes(
            QueueUrl=url, AttributeNames=["ApproximateNumberOfMessages"]
        )["Attributes"]
        depth = int(attrs["ApproximateNumberOfMessages"])
        level = "FAIL" if depth else "ok"
        print(f"[{level:<4}] sqs:{name}: {depth} message(s) waiting")
        if depth:
            waiting.append(name)
    return waiting


if __name__ == "__main__":
    print("needs attention:", check_dead_letter_queues())

Quick Quiz 1 / 3

On-demand DynamoDB table မှာ table-wide consumed capacity နိမ့်နေပေမယ့် WriteThrottleEvents ရှိနေတယ်။ ဖြစ်နိုင်ခြေ အများဆုံး root cause က ဘာလဲ?

Quick Quiz 2 / 3

Role ကို ဖျက်ပြီး နာမည်တူ ပြန်ဖန်တီးလိုက်ပြီးနောက် cross-account AssumeRole fail ဖြစ်ပြီး target role ရဲ့ trust policy မှာ 'AROA...' ID ပေါ်နေတယ်။ ဘာလုပ်ရမလဲ?

Quick Quiz 3 / 3

Incident အတွင်း Lambda throttle ကို ချက်ချင်း ငြိမ်အောင် account concurrency quota တိုးလိုက်တယ်။ Review method အရ နောက်ထပ် ဘာလုပ်ရဦးမလဲ?

မှတ်ထားရမယ့် အချက်များ

  • Symptom → evidence → root cause → fix → prevention ကို incident တိုင်းမှာ အစဉ်လိုက် လုပ်ပါ
  • Root cause က trigger မဟုတ်ပါ - design ဆုံးဖြတ်ချက် (သို့) guardrail ပျောက်နေတာ အထိ 'ဘာကြောင့်' ဆက်မေးပါ
  • Containment လုပ်တဲ့အခါ evidence ကို ထိန်းသိမ်းပြီး တစ်ကြိမ်မှာ change တစ်ခုပဲ လုပ်ပါ
  • Fix တိုင်းကို alarm, SCP, baseline control (သို့) CI check အဖြစ် ပြောင်းမှ ထပ်မဖြစ်တော့ပါဘူး

AWS Well-Architected Framework — AWS Documentation

Troubleshoot IAM access denied errors — AWS Documentation

Analyzing log data with CloudWatch Logs Insights — AWS Documentation

နောက်ဆုံးပြင်ဆင်ရက်

Progress ကို ဤ browser (ဤစက်) တွင်သာ သိမ်းထားပါသည်။ အခြားစက်များနှင့် sync မလုပ်ပါ။

ဤသင်ခန်းစာတွင် အမှားတွေ့ပါက အကြောင်းကြားရန်သင့် email app ကို ဤသင်ခန်းစာလိပ်စာ ဖြည့်ပြီးသားဖြင့် ဖွင့်ပေးပါမည် — သင်ကိုယ်တိုင် ပို့မှသာ ပို့မည်ဖြစ်သည်။

Exercises: Architecture Review နဲ့ Troubleshooting Scenario ၆ ခု | Thuta Learning