ရိုးရိုးလေး ရှင်းပြမယ်
အိမ်က လျှပ်စစ်မီတာ ဥပမာ
လျှပ်စစ်ဘေလ် တစ်လုံးတည်း ရပြီး ဘယ်အခန်းက ဘယ်လောက် သုံးလဲ မသိရင် ချွေတာဖို့ ခက်ပါတယ် — ဒါကြောင့် ပထမဆုံး အခန်းတိုင်းမှာ မီတာ တပ်ရပါတယ် (AWS မှာဆိုရင် tag တွေ)။ ပြီးရင် လူမရှိတဲ့ အခန်းက မီးတွေကို ပိတ်ပါ (idle resource)၊ လူတစ်ယောက်တည်းအတွက် ခန်းမကြီး တစ်ခုလုံးကို air-con မဖွင့်ပါနဲ့ (right-sizing)၊ မီးချောင်းကို ပိုချွေတာတဲ့ အမျိုးအစား ပြောင်းပါ (Graviton)။
နေ့တိုင်း သေချာ သုံးမယ့် ပမာဏအတွက် နှစ်ရှည် စာချုပ်ချုပ်ရင် ဈေးသက်သာပါတယ် (Savings Plans)၊ ချိန်ရွှေ့လို့ရတဲ့ အလုပ်တွေကို ဈေးပေါတဲ့ အချိန်မှာ လုပ်ပါ (Spot)။ အစဉ်က အရေးကြီးပါတယ်: မြင်အောင်လုပ်၊ ဖြုန်းတီးမှုကို ဖယ်ရှား၊ ပြီးမှ commit လုပ်ပါ။
Problem → Why → Solution
၆ လအတွင်း bill နှစ်ဆကျော် တက်သွားတယ်
Startup တစ်ခုရဲ့ လစဉ် AWS bill က ၆ လအတွင်း နှစ်ဆကျော် တက်သွားပြီး ဘာကြောင့်လဲ ဘယ်သူမှ မသိပါဘူး။ Team အားလုံး account တစ်ခုတည်းကို မျှသုံးပြီး tag မရှိပါဘူး။ Cost Explorer မှာ အကြီးဆုံး line item က 'EC2 - Other' ဖြစ်နေပါတယ် — ဒါက instance မဟုတ်ဘဲ NAT Gateway၊ EBS volume၊ snapshot နဲ့ data transfer တွေ ပေါင်းထားတဲ့ category ပါ။
စုံစမ်းကြည့်တော့ private subnet ထဲက data pipeline က S3 ကနေ TB ချီတဲ့ data ကို NAT Gateway ကနေ ဖတ်နေတာ (GB တိုင်းကို processing fee ပေးနေရတာ)၊ ဖျက်ပြီးသား instance တွေက ကျန်ခဲ့တဲ့ unattached EBS volume ၁၄၀ နဲ့ retention မထားတဲ့ debug log တွေကို တွေ့ရပါတယ်။ တစ်ခုချင်းစီက သေးသေးလေးလို့ ထင်ရပေမယ့် ပေါင်းလိုက်တော့ bill ရဲ့ သုံးပုံတစ်ပုံ ဖြစ်နေပါတယ်။
aws ce get-cost-and-usage \
--time-period Start=2026-10-01,End=2026-11-01 \
--granularity MONTHLY --metrics UnblendedCost \
--group-by Type=DIMENSION,Key=SERVICE \
--query 'ResultsByTime[0].Groups[].[Keys[0],Metrics.UnblendedCost.Amount]' \
--output text | sort -k2 -nr | head -5
# EC2 - Other <- NAT, EBS, snapshots, data transfer
# Amazon Elastic Compute Cloud - Compute
# ...Cost က architecture ရဲ့ property တစ်ခုပါ
Visibility နဲ့ ownership မရှိရင် ဖြုန်းတီးမှုက တိတ်တဆိတ် စုပုံလာပါတယ်။ အကြီးဆုံး ကုန်ကျစရိတ်တွေက 'EC2 - Other' နဲ့ data transfer လို category တွေထဲ ပုန်းနေလို့ instance price ကိုပဲ ကြည့်ရင် လုံးဝ မတွေ့ရပါဘူး။ Bill ရောက်မှ သိတာက တစ်လ နောက်ကျပြီးသားပါ။
မြင်အောင်လုပ် → စောင့်ကြည့် → ချွေတာ
- Cost allocation tag
- Billing console မှာ activate လုပ်ထားတဲ့ tag key (ဥပမာ team၊ cost-center) — activate လုပ်ပြီးမှ Cost Explorer နဲ့ billing data ထဲမှာ အဲဒီ tag နဲ့ group လုပ်လို့ ရပါတယ်။
Visibility က အရင်လာပါတယ်။ Cost Explorer က service၊ account၊ Region၊ usage type နဲ့ tag အလိုက် group လုပ်ပြီး trend ကြည့်ဖို့ အမြန်ဆုံး နည်းပါ။ အသေးစိတ် လိုရင် AWS Data Exports (Cost and Usage Report 2.0 အပါအဝင်) က line-item billing data ကို S3 ဆီ ပို့ပေးလို့ Athena နဲ့ query လုပ်လို့ ရပါတယ်။ Tag က ownership ရဲ့ အခြေခံပါ: team တစ်ခုစီရဲ့ ကုန်ကျစရိတ်ကို မြင်ရမှ team တွေက တာဝန်ယူကြပါတယ်။
Guardrail တွေက ဒုတိယ အဆင့်ပါ။ AWS Budgets က actual နဲ့ forecasted spend တွေကို threshold နဲ့ နှိုင်းယှဉ်ပြီး alert ပို့ပေးတယ်၊ budget action နဲ့ IAM policy (သို့) SCP တပ်တာ၊ instance ရပ်တာလို တုံ့ပြန်မှုကိုလည်း လုပ်နိုင်ပါတယ်။ Cost Anomaly Detection က machine learning နဲ့ ပုံမှန် spend pattern ကို သင်ယူပြီး မမျှော်လင့်တဲ့ တက်လာမှုကို ရက်ပိုင်းအတွင်း alert ပို့ပေးလို့ bill ရောက်မှ သိရတာမျိုး မဖြစ်တော့ပါဘူး။
ပြီးမှ ချွေတာပါ — အစဉ်အတိုင်း။ ပထမ waste ကို ဖယ်ပါ: idle resource၊ unattached EBS volume၊ မလိုတော့တဲ့ snapshot။ ဒုတိယ right-size လုပ်ပါ: AWS Compute Optimizer က CloudWatch utilization ကို ကြည့်ပြီး EC2၊ Auto Scaling group၊ EBS၊ Lambda နဲ့ Fargate အတွက် size အသေး (သို့) Graviton ကို အကြံပေးပါတယ်။ Graviton (Arm-based) instance တွေက workload အများစုမှာ price-performance ပိုကောင်းပေမယ့် arm64 build လိုလို့ ကိုယ့် workload နဲ့ တိုင်းတာကြည့်ပါ။
တတိယမှ commit လုပ်ပါ။ Savings Plans က ၁ နှစ် (သို့) ၃ နှစ်အတွက် တစ်နာရီ $ ပမာဏ တစ်ခုကို commit လုပ်ပြီး discount ရပါတယ်: Compute Savings Plans က EC2 instance family၊ Region၊ OS ပြောင်းလို့ရပြီး Fargate နဲ့ Lambda ကိုပါ ဖုံးပါတယ်၊ EC2 Instance Savings Plans က Region တစ်ခုထဲက family တစ်ခုနဲ့ ချည်ထားလို့ discount ပိုများပေမယ့် flexibility နည်းပါတယ်။ Reserved Instances ကတော့ RDS၊ ElastiCache၊ OpenSearch၊ Redshift လို database service တွေအတွက် အဓိက commitment ရွေးချယ်မှု ဖြစ်နေဆဲပါ။ Spot က AWS ရဲ့ အပို capacity ကို discount ကြီးကြီးနဲ့ ရောင်းတာဖြစ်ပြီး ၂ မိနစ် interruption notice နဲ့ ပြန်ယူနိုင်လို့ stateless၊ batch၊ CI လို fault-tolerant workload တွေအတွက်ပဲ သင့်တော်ပါတယ်။
| Lever | အသင့်တော်ဆုံး | သတိထားရမှာ |
|---|---|---|
| Savings Plans | တည်ငြိမ်တဲ့ baseline compute | Peak ကို commit မလုပ်ပါနဲ့ |
| Reserved Instances | RDS၊ ElastiCache လို database | Engine/size ပြောင်းရင် flexibility နည်း |
| Spot | Batch၊ CI၊ stateless fleet | Interruption — instance type အမျိုးမျိုး သုံးပါ |
| Graviton | Linux workload အများစု | arm64 build နဲ့ dependency တွေ |
| Right-sizing | Utilization နိမ့်တဲ့ အရာအားလုံး | Peak နဲ့ memory ကိုပါ ကြည့်ပါ |
THE NAT GATEWAY TRAP AND ITS FIX
--------------------------------
BEFORE AFTER
[private subnet] [private subnet]
| 5 TB/month to S3 | 5 TB/month to S3
v v
[NAT Gateway] <- per hour + per GB [S3 gateway endpoint]
| processed | no hourly, no per-GB fee
v v
[Internet gateway] --> [Amazon S3] [Amazon S3]
Same for DynamoDB. Other services: interface endpoints (cheaper per GB
than NAT, but billed per hour per AZ) - do the maths per service.- See it: tags + Cost Explorer
- Guard it: Budgets + anomaly alerts
- Remove waste (idle, unattached)
- Right-size, then move to Graviton
- Commit last: Savings Plans / RIs
Commitment ကို အရင် ဝယ်လိုက်ရင် ဖြုန်းတီးမှုကို ၁ နှစ် (သို့) ၃ နှစ်စာ lock လုပ်လိုက်တာပါ။ အစဉ်ကို ပြောင်းပြန် မလုပ်ပါနဲ့။
Team tag နဲ့ service အလိုက် cost ခွဲကြည့်ခြင်း
aws ce get-cost-and-usage \
--time-period Start=2026-10-01,End=2026-11-01 \
--granularity MONTHLY \
--metrics UnblendedCost \
--group-by Type=DIMENSION,Key=SERVICE Type=TAG,Key=team--group-by ကို နှစ်ခုအထိ ပေါင်းလို့ရပါတယ်: ဒီမှာ service နဲ့ team tag ပါ။ Tag မပါတဲ့ resource တွေက 'team$' (value အလွတ်) အောက်မှာ ပေါ်လာပါတယ် — အဲဒီ ပမာဏက ကိုယ့် tagging coverage ကို တိုင်းတာတဲ့ ကိန်းဂဏန်း ကောင်းတစ်ခုပါ။ End date က exclusive ဖြစ်လို့ 2026-11-01 က အောက်တိုဘာ တစ်လလုံးကို ဆိုလိုပါတယ်။
Waste finder: unattached volume၊ orphaned snapshot၊ idle IP
ဒီ script က read-only ပါ — ဘာမှ မဖျက်ပါဘူး။ Unattached EBS volume တွေ၊ source volume မရှိတော့တဲ့ snapshot တွေ (ကိုယ့် AMI ကို back လုပ်နေတာတွေ မပါ) နဲ့ ဘာနဲ့မှ မချိတ်ထားတဲ့ Elastic IP တွေကို ရှာပြီး လစဉ် ကုန်ကျစရိတ်ကို ခန့်မှန်းပါတယ်။ ဈေးနှုန်းတွေက us-east-1 အတွက် ခန့်မှန်းခြေ ဖြစ်ပြီး pricing page မှာ အမြဲ ပြန်စစ်ပါ။ Account တစ်ခုစီ၊ Region တစ်ခုစီမှာ run ဖို့ လိုပါတယ်။
import boto3
# Approximate us-east-1 prices in USD - always confirm on the pricing page
GB_MONTH = {"gp2": 0.10, "gp3": 0.08}
IPV4_MONTH = 0.005 * 730 # public IPv4 address: hourly rate x hours per month
ec2 = boto3.client("ec2", region_name="us-east-1")
ACCOUNT = boto3.client("sts").get_caller_identity()["Account"]
def name_of(resource):
for tag in resource.get("Tags", []):
if tag["Key"] == "Name":
return tag["Value"]
return "(no Name tag)"
def find_waste():
findings = []
volumes = []
for page in ec2.get_paginator("describe_volumes").paginate():
volumes.extend(page["Volumes"])
live_ids = {v["VolumeId"] for v in volumes}
for v in volumes:
if v["State"] == "available": # not attached to anything
cost = v["Size"] * GB_MONTH.get(v["VolumeType"], 0.10)
detail = f"{v['Size']} GiB {v['VolumeType']}"
findings.append(("unattached volume", name_of(v), detail, cost))
# Snapshots that back one of our AMIs are still in use
ami_snaps = {
bdm["Ebs"]["SnapshotId"]
for image in ec2.describe_images(Owners=["self"])["Images"]
for bdm in image.get("BlockDeviceMappings", [])
if "SnapshotId" in bdm.get("Ebs", {})
}
pages = ec2.get_paginator("describe_snapshots").paginate(
OwnerIds=["self"], Filters=[{"Name": "owner-id", "Values": [ACCOUNT]}]
)
for page in pages:
for s in page["Snapshots"]:
if s["VolumeId"] not in live_ids and s["SnapshotId"] not in ami_snaps:
detail = f"from {s['VolumeSize']} GiB volume"
findings.append(("orphaned snapshot", name_of(s), detail, None))
for a in ec2.describe_addresses()["Addresses"]:
if "AssociationId" not in a: # allocated but not attached
findings.append(("idle Elastic IP", name_of(a), "public IPv4", IPV4_MONTH))
return sorted(findings, key=lambda f: (f[0], f[1]))
if __name__ == "__main__":
total = 0.0
for kind, name, detail, cost in find_waste():
estimate = f"~{cost:.2f} USD/month" if cost else "review manually"
print(f"{kind:<18} {name:<21} {detail:<20} {estimate}")
total += cost or 0
print(f"Estimated waste: ~{total:.2f} USD/month (plus snapshot storage)")Browser ထဲမှာ run လို့ မရပါ
ဒီ code ဟာ AWS account အစစ်ပေါ်မှာ run ရမယ့် code ဖြစ်လို့ browser playground ထဲမှာ run လို့ မရပါ။ ကိုယ့် terminal (သို့) AWS CloudShell ထဲမှာ စမ်းပါ။
Code ကို တစ်ပိုင်းချင်း ရှင်းပြမယ်
- Paginate everything
for page in ec2.get_paginator("describe_volumes").paginate():Account ကြီးတွေမှာ volume နဲ့ snapshot ထောင်ချီ ရှိနိုင်ပြီး describe call တစ်ခုက page တစ်ခုပဲ ပြန်ပေးပါတယ်။ Paginator မသုံးရင် ပထမ page ပြီးတာနဲ့ waste ကို 'ရှာမတွေ့တော့ဘူး' လို့ မှားပြီး ထင်သွားပါလိမ့်မယ်။
- Unattached = state 'available'
if v["State"] == "available":EBS volume က instance နဲ့ မချိတ်ထားရင်တောင် provisioned GiB အလိုက် ပိုက်ဆံ ကျနေဆဲပါ။ 'available' state က ဘာနဲ့မှ မချိတ်ထားဘူးလို့ ဆိုလိုပါတယ်။ ဖျက်ခင် snapshot ယူထားတာ ပိုလုံခြုံပါတယ်။
- Orphaned, but not AMI-backing
if s["VolumeId"] not in live_ids and s["SnapshotId"] not in ami_snaps:Source volume ဖျက်ပြီးသား snapshot တွေက waste ဖြစ်နိုင်ပေမယ့် ကိုယ့် AMI ကို back လုပ်နေတဲ့ snapshot တွေကတော့ AMI deregister မလုပ်မချင်း လိုအပ်နေဆဲပါ။ Compliance အတွက် ထိန်းထားရတဲ့ snapshot တွေလည်း ရှိနိုင်လို့ cost ကို 'review manually' လို့ပဲ ပြပါတယ်။
- Idle public IPv4
if "AssociationId" not in a:Public IPv4 address တွေက တစ်နာရီချင်း ကျသင့်ပါတယ် — instance နဲ့ ချိတ်ထားသည်ဖြစ်စေ မချိတ်ထားသည်ဖြစ်စေ။ ချိတ်မထားတဲ့ Elastic IP ကတော့ အသုံးမဝင်ဘဲ ပိုက်ဆံ ကုန်နေတာ သေချာပါတယ်။
idle Elastic IP old-bastion-ip public IPv4 ~3.65 USD/month
orphaned snapshot pre-migration-backup from 200 GiB volume review manually
unattached volume jenkins-tmp 100 GiB gp3 ~8.00 USD/month
unattached volume old-build-cache 500 GiB gp2 ~50.00 USD/month
Estimated waste: ~61.65 USD/month (plus snapshot storage)Guardrail: tag၊ Budgets နဲ့ anomaly alert
Tag key တွေကို activate လုပ်မှ billing data ထဲ ပေါ်ပါတယ်။ ပြီးရင် forecast က budget ကျော်မယ့်အခါ (actual မကျော်ခင်) alert ပို့တဲ့ budget တစ်ခုနဲ့ service အလိုက် anomaly monitor တစ်ခု ထည့်ပါ။ Anomaly ရဲ့ total impact $100 ကျော်မှ နေ့စဉ် email ပို့ပါတယ်။
[
{
"Notification": {
"NotificationType": "FORECASTED",
"ComparisonOperator": "GREATER_THAN",
"Threshold": 100,
"ThresholdType": "PERCENTAGE"
},
"Subscribers": [{ "SubscriptionType": "EMAIL", "Address": "finops@example.com" }]
},
{
"Notification": {
"NotificationType": "ACTUAL",
"ComparisonOperator": "GREATER_THAN",
"Threshold": 80,
"ThresholdType": "PERCENTAGE"
},
"Subscribers": [{ "SubscriptionType": "EMAIL", "Address": "finops@example.com" }]
}
]aws ce update-cost-allocation-tags-status \
--cost-allocation-tags-status TagKey=team,Status=Active TagKey=env,Status=Active
BUDGET='BudgetName=monthly-total,BudgetLimit={Amount=10000,Unit=USD},'
BUDGET+='TimeUnit=MONTHLY,BudgetType=COST'
aws budgets create-budget \
--account-id 111122223333 \
--budget "$BUDGET" \
--notifications-with-subscribers file://notifications.json
MONITOR='{"MonitorName":"by-service","MonitorType":"DIMENSIONAL",'
MONITOR+='"MonitorDimension":"SERVICE"}'
MONITOR_ARN=$(aws ce create-anomaly-monitor --anomaly-monitor "$MONITOR" \
--query MonitorArn --output text)
SUB_ARN=$(aws ce create-anomaly-subscription \
--anomaly-subscription file://anomaly-subscription.json \
--query SubscriptionArn --output text){
"SubscriptionName": "daily-anomalies",
"MonitorArnList": [
"arn:aws:ce::111122223333:anomalymonitor/0a1b2c3d-4e5f-6789-abcd-ef0123456789"
],
"Subscribers": [{ "Type": "EMAIL", "Address": "finops@example.com" }],
"Frequency": "DAILY",
"ThresholdExpression": {
"Dimensions": {
"Key": "ANOMALY_TOTAL_IMPACT_ABSOLUTE",
"MatchOptions": ["GREATER_THAN_OR_EQUAL"],
"Values": ["100"]
}
}
}Cost trap တွေကို ပြင်ခြင်း
- NAT Gateway data processing — S3 နဲ့ DynamoDB traffic အတွက် gateway VPC endpoint (အခမဲ့) ထည့်ပါ၊ အခြား service တွေအတွက် interface endpoint နဲ့ NAT ကို GB volume နဲ့ တွက်ချက် နှိုင်းယှဉ်ပါ
- Cross-AZ data transfer — AZ ကြား traffic ကို direction နှစ်ဖက်လုံးမှာ GB အလိုက် ကျသင့်ပါတယ်၊ chatty microservice နဲ့ replication traffic ကို ကြည့်ပြီး AZ-local routing ကို စဉ်းစားပါ
- Inter-Region data transfer — cross-Region replication နဲ့ backup copy တိုင်းမှာ GB အလိုက် ကျသင့်လို့ တကယ် လိုတာကိုပဲ replicate လုပ်ပါ
- Idle resource — dev/test environment တွေကို ညနဲ့ စနေ၊ တနင်္ဂနွေ ပိတ်ပါ၊ ရုံးချိန် တစ်ပတ် ၆၀ နာရီက ၁၆၈ နာရီရဲ့ ၃၆% ပဲ ရှိပါတယ်
- Unattached EBS volume နဲ့ snapshot အဟောင်း — Amazon Data Lifecycle Manager (သို့) AWS Backup lifecycle နဲ့ snapshot retention ကို အလိုအလျောက် လုပ်ပါ
- Log retention — log group တိုင်းမှာ retention ထားပြီး ingest လုပ်တဲ့ log level ကို ထိန်းပါ
# S3 traffic from private subnets stops going through the NAT Gateway
aws ec2 create-vpc-endpoint \
--vpc-id vpc-0a1b2c3d4e5f67890 \
--vpc-endpoint-type Gateway \
--service-name com.amazonaws.us-east-1.s3 \
--route-table-ids rtb-0a1b2c3d4e5f67890 rtb-0f9e8d7c6b5a43210
aws logs put-retention-policy \
--log-group-name /aws/lambda/checkout --retention-in-days 30
aws s3api put-bucket-lifecycle-configuration \
--bucket app-logs-111122223333 \
--lifecycle-configuration file://lifecycle.json
# Right-sizing and commitment recommendations
aws compute-optimizer update-enrollment-status --status Active
aws compute-optimizer get-ec2-instance-recommendations \
--query 'instanceRecommendations[].[instanceArn,finding]' --output table
aws ce get-savings-plans-purchase-recommendation \
--savings-plans-type COMPUTE_SP --term-in-years ONE_YEAR \
--payment-option NO_UPFRONT --lookback-period-in-days THIRTY_DAYS{
"Rules": [
{
"ID": "logs-tiering",
"Status": "Enabled",
"Filter": { "Prefix": "logs/" },
"Transitions": [
{ "Days": 30, "StorageClass": "STANDARD_IA" },
{ "Days": 90, "StorageClass": "GLACIER_IR" }
],
"Expiration": { "Days": 365 },
"NoncurrentVersionExpiration": { "NoncurrentDays": 30 },
"AbortIncompleteMultipartUpload": { "DaysAfterInitiation": 7 }
}
]
}Lifecycle က အမြဲ ချွေတာတာ မဟုတ်ပါ
Standard-IA နဲ့ Glacier class တွေမှာ minimum storage duration နဲ့ object တစ်ခုချင်း minimum billable size ရှိပြီး transition request တစ်ခုချင်းလည်း ကျသင့်ပါတယ်။ သေးငယ်တဲ့ object သန်းချီ ရှိရင် transition လုပ်တာက ပိုဈေးကြီးနိုင်ပါတယ်။ Access pattern မသိရင် S3 Intelligent-Tiering ကို စဉ်းစားပါ။
Production မှာ
FinOps ကို production မှာ ဘယ်လို လုပ်ကြလဲ
Tagging policy ကို IaC မှာ default tag အဖြစ် ထည့်ပြီး AWS Organizations ရဲ့ tag policy နဲ့ စစ်ပါတယ်။ Data Exports ကနေ Athena နဲ့ team တစ်ခုစီရဲ့ cost report (showback) ကို အလိုအလျောက် ထုတ်ပြီး အပတ်စဉ် cost review မှာ ကြည့်ပါတယ်။ ရင့်ကျက်တဲ့ team တွေက 'order တစ်ခုချင်းရဲ့ cost' လို unit economics ကို ကြည့်ပါတယ် — traffic တက်လို့ bill တက်တာက ပုံမှန်ပါ၊ order တစ်ခုချင်း cost တက်တာကတော့ ပြဿနာပါ။
Savings Plans ကို peak ပေါ်မှာ မဟုတ်ဘဲ တည်ငြိမ်တဲ့ baseline ပေါ်မှာပဲ commit လုပ်ပြီး coverage နဲ့ utilization ကို လစဉ် ကြည့်ပါတယ်၊ purchase တစ်ခုတည်း ကြီးကြီး ဝယ်တာထက် အချိန်ခွဲပြီး သေးသေး ဝယ်လေ့ ရှိပါတယ်။ Container နဲ့ CI fleet တွေမှာ On-Demand baseline နဲ့ Spot ကို ရောပြီး instance type အမျိုးမျိုး သုံးကာ capacity-optimized allocation နဲ့ interruption ကို လျှော့ပါတယ်။ Engineer တွေ ကုန်ကျစရိတ်ကို မြင်ရအောင် pull request ထဲမှာ IaC cost estimate ပြတာမျိုးလည်း လုပ်ကြပါတယ်။
Account တိုင်းမှာ budget နဲ့ anomaly alert ကို IaC baseline ထဲ ထည့်ထားလို့ account အသစ် ဖွင့်တာနဲ့ guardrail တွေ အလိုအလျောက် ပါလာပါတယ်။ Alert တိုင်းမှာ ပိုင်ရှင် team ရှိပါတယ်။
အမှားများ
အဖြစ်များတဲ့ အမှားတွေ
Right-size မလုပ်ခင် commit လုပ်ခြင်း
ကြီးလွန်းနေတဲ့ fleet ပေါ်မှာ ၃ နှစ် Savings Plan ဝယ်လိုက်ရင် ဖြုန်းတီးမှုကို discount နဲ့ lock လုပ်လိုက်တာပါ။ နောက်မှ right-size လုပ်တဲ့အခါ commitment ကို ပြည့်အောင် မသုံးနိုင်တော့ဘဲ အသုံးမပြုတဲ့ commitment အတွက် ပေးနေရပါတယ်။
S3 နဲ့ DynamoDB traffic ကို NAT Gateway ကနေ ဖြတ်ခြင်း
NAT Gateway က ဖြတ်သွားတဲ့ GB တိုင်းကို processing fee ယူပါတယ်။ S3 နဲ့ DynamoDB အတွက် gateway endpoint က အခမဲ့ဖြစ်ပြီး route table ထဲမှာ entry တစ်ခု ထည့်ရုံပါပဲ — data pipeline တွေမှာ အမြန်ဆုံး ချွေတာနိုင်တဲ့ နည်းတစ်ခုပါ။
Stateful workload ကို Spot ပေါ် တင်ခြင်း
Spot instance ကို ၂ မိနစ် notice နဲ့ ပြန်ယူနိုင်ပါတယ်။ Database primary လို stateful single instance ကို Spot ပေါ် တင်ရင် ချွေတာလိုက်တဲ့ ပိုက်ဆံထက် outage က ပိုဈေးကြီးပါတယ်။ Checkpoint လုပ်နိုင်တဲ့၊ ပြန် retry လုပ်နိုင်တဲ့ work ကိုပဲ Spot ပေါ် တင်ပါ။
Average CPU ကိုပဲ ကြည့်ပြီး right-size လုပ်ခြင်း
Average CPU 10% ဖြစ်ပေမယ့် memory ပြည့်နေတာ (သို့) နေ့စဉ် batch peak ရှိနေတာ ဖြစ်နိုင်ပါတယ်။ EC2 memory metric က CloudWatch agent မထည့်ရင် မရလို့ Compute Optimizer recommendation တွေကို peak နဲ့ memory ကိုပါ ကြည့်ပြီးမှ apply လုပ်ပါ။
💰 Cost & Cleanup
ဒီ lab ရဲ့ script က read-only ဖြစ်လို့ API call တွေက အခမဲ့ပါ။ Cost Explorer console က အခမဲ့ ဖြစ်ပေမယ့် Cost Explorer API request တစ်ခုချင်း ကျသင့်ပါတယ် (ခန့်မှန်းခြေ request တစ်ခု ၁ cent လောက်၊ pricing page မှာ စစ်ပါ) — loop ထဲမှာ ခေါ်ရင် သတိထားပါ။ Cost Anomaly Detection က အခမဲ့ပါ။ Budget အခြေခံ tracking က များသောအားဖြင့် အခမဲ့ ဖြစ်ပြီး budget action တွေမှာ free allowance ကျော်ရင် နေ့စဉ် ကျသင့်ပါတယ်။ Data Exports က အခမဲ့ ဖြစ်ပေမယ့် S3 storage နဲ့ Athena query ကုန်ကျစရိတ် ရှိပါတယ်။ Compute Optimizer ရဲ့ default recommendation တွေ အခမဲ့ ဖြစ်ပြီး enhanced infrastructure metrics က ကျသင့်ပါတယ်။ Gateway VPC endpoint က အခမဲ့ပါ။
Lab ပြီးရင် test budget နဲ့ anomaly subscription/monitor ကို ဖျက်ပါ။ Gateway endpoint၊ log retention နဲ့ lifecycle rule ကတော့ ပိုက်ဆံ ချွေတာပေးတာမို့ ထားခဲ့ပါ။
စမ်းပြီးရင် ဖျက်ဖို့ command
aws budgets delete-budget --account-id 111122223333 --budget-name monthly-total
aws ce delete-anomaly-subscription --subscription-arn "$SUB_ARN"
aws ce delete-anomaly-monitor --monitor-arn "$MONITOR_ARN"Mini challenge
Stopped instance တွေရဲ့ ဝှက်ထားတဲ့ storage cost
Stopped EC2 instance တွေက compute ကို ပိုက်ဆံ မကျပေမယ့် ချိတ်ထားတဲ့ EBS volume တွေအတွက် ပိုက်ဆံ ကျနေဆဲပါ။ Stopped instance တစ်ခုချင်းစီရဲ့ EBS storage ကို ရှာပြီး လစဉ် ကုန်ကျစရိတ်ကို ခန့်မှန်းတဲ့ function တစ်ခု ရေးပါ။
- instance-state-name filter နဲ့ stopped instance တွေကိုပဲ ရှာရမယ် (paginator သုံးပါ)
- Instance တစ်ခုစီနဲ့ ချိတ်ထားတဲ့ volume တွေရဲ့ GiB ကို ပေါင်းရမယ်
- Example ထဲက GB_MONTH ဈေးနှုန်း table နဲ့ လစဉ် cost ခန့်မှန်းရမယ်
- Instance ရဲ့ Name tag ကို print ထုတ်ရမယ်
ရလဒ်: 8 GiB gp2 root volume နဲ့ 300 GiB gp3 data volume ပါတဲ့ stopped instance 'legacy-reporting' အတွက် 'stopped instance legacy-reporting: 308 GiB EBS, ~24.80 USD/month' ထွက်ပြီး running instance တွေ မပါရပါဘူး။
အရိပ်အမြွက် ကြည့်ရန်
describe_volumes မှာ attachment.instance-id filter နဲ့ instance တစ်ခုရဲ့ volume တွေကို ရနိုင်ပါတယ်။ Root volume ကိုလည်း မမေ့ပါနဲ့ — သူလည်း EBS volume ပါပဲ။
အဖြေ ကြည့်ရန်
import boto3
GB_MONTH = {"gp2": 0.10, "gp3": 0.08} # approximate us-east-1 USD
ec2 = boto3.client("ec2", region_name="us-east-1")
def name_of(resource):
for tag in resource.get("Tags", []):
if tag["Key"] == "Name":
return tag["Value"]
return "(no Name tag)"
def monthly_cost(volumes):
return sum(v["Size"] * GB_MONTH.get(v["VolumeType"], 0.10) for v in volumes)
def stopped_instance_storage():
results = []
pages = ec2.get_paginator("describe_instances").paginate(
Filters=[{"Name": "instance-state-name", "Values": ["stopped"]}]
)
for page in pages:
for reservation in page["Reservations"]:
for inst in reservation["Instances"]:
iid = inst["InstanceId"]
attached = {"Name": "attachment.instance-id", "Values": [iid]}
volumes = ec2.describe_volumes(Filters=[attached])["Volumes"]
gib = sum(v["Size"] for v in volumes)
results.append((name_of(inst), gib, monthly_cost(volumes)))
return sorted(results)
if __name__ == "__main__":
for name, gib, cost in stopped_instance_storage():
print(f"stopped instance {name}: {gib} GiB EBS, ~{cost:.2f} USD/month")Quick Quiz 1 / 3
Quick Quiz 2 / 3
Quick Quiz 3 / 3
မှတ်ထားရမယ့် အချက်များ
- မြင်အောင်လုပ်ပါ: cost allocation tag တွေကို activate လုပ်ပြီး Cost Explorer နဲ့ Data Exports ကို သုံးပါ
- စောင့်ကြည့်ပါ: forecast budget alert နဲ့ Cost Anomaly Detection က bill မရောက်ခင် သိစေပါတယ်
- အစဉ်အတိုင်း: waste ဖယ် → right-size/Graviton → ပြီးမှ baseline ပေါ် Savings Plans/RI commit
- Spot က interrupt ခံနိုင်တဲ့ work အတွက်ပဲ၊ instance type အမျိုးမျိုးနဲ့ သုံးပါ
- NAT data processing၊ cross-AZ/inter-Region transfer၊ unattached EBS၊ log retention က အဖြစ်အများဆုံး trap တွေပါ
AWS Cost Management User Guide — AWS Documentation
Savings Plans User Guide — AWS Documentation
AWS Compute Optimizer User Guide — AWS Documentation