เป้าหมาย
เปลี่ยนจาก "บิลเดือนนี้แพง ไม่รู้ทำไม" เป็น "รู้ว่าเงินทุกบาทไปที่ทีมไหน/ฟีเจอร์ไหน และลดได้ 20–40% โดยไม่ลดความน่าเชื่อถือ" ด้วยลำดับที่ถูก: มองเห็น → ทิ้งของเสีย → ปรับขนาด → เปลี่ยนสถาปัตยกรรม → ค่อยผูกสัญญา
ลำดับที่ถูก (ผิดลำดับ = ผูกสัญญากับของเสีย)
| ขั้น | ทำอะไร | ผลทั่วไป |
|---|---|---|
| 1. มองเห็น | tag + cost allocation tags + CUR/Cost Explorer ต่อทีม/ต่อ env | รู้ว่าใครใช้ |
| 2. ทิ้งของเสีย | EBS ไม่ได้ต่อ, snapshot เก่า, IPv4 ว่าง, NAT ที่ไม่จำเป็น, dev เปิด 24/7 | เร็วที่สุด เสี่ยงน้อยสุด |
| 3. rightsizing | ลดขนาดเครื่อง/memory ตาม utilization จริง | 10–30% ของ compute |
| 4. สถาปัตยกรรม | Graviton, Spot, serverless, storage class, ลด data transfer | ลดต่อหน่วยระยะยาว |
| 5. ผูกสัญญา | Savings Plans / Reserved | ลดส่วนที่เหลือที่ "คงที่" |
ผูกสัญญา: Savings Plans vs Reserved
| Compute Savings Plans | EC2 Instance Savings Plans | Reserved Instances (RDS, ElastiCache, OpenSearch ฯลฯ) | |
|---|---|---|---|
| ส่วนลดสูงสุด (โดยประมาณ) | ~66% | ~72% | แตกต่างตามบริการ |
| ยืดหยุ่น | ข้าม family, region, OS, และใช้กับ Fargate + Lambda ได้ | ล็อก family + region (เปลี่ยน size/OS ได้) | ล็อกเงื่อนไขมากกว่า |
| ผูก | $/ชม. 1 หรือ 3 ปี | $/ชม. 1 หรือ 3 ปี | 1 หรือ 3 ปี |
- ผูก ไม่เกิน baseline ต่ำสุด ของการใช้งาน (ดูกราฟ 30–60 วัน) — ส่วน peak ปล่อย on-demand/Spot
- ทยอยซื้อเป็นก้อนเล็กทุกเดือน/ไตรมาส แทนก้อนใหญ่ครั้งเดียว (ลดความเสี่ยงเมื่อสถาปัตยกรรมเปลี่ยน)
- มี Database Savings Plans (ประกาศ 2 ธ.ค. 2025) ผูก $/ชม. 1 ปี ไม่ต้องจ่ายล่วงหน้า ใช้ได้ข้าม engine/family/region กับ Aurora, RDS, DynamoDB, ElastiCache, DocumentDB, Neptune, Keyspaces, Timestream, DMS (มี.ค. 2026 เพิ่ม OpenSearch Service และ Neptune Analytics) — ส่วนลดสูงสุดราว 35% (serverless) / 20% (provisioned instance) / 12–18% (DynamoDB/Keyspaces throughput) ต่ำกว่า compute · ใช้ซ้อนกับ RDS Reserved Instances หรือ DynamoDB reserved capacity บน workload เดียวกันไม่ได้
⚠️ ต้องตรวจสอบ: เปอร์เซ็นต์ส่วนลด เงื่อนไข term/payment ของ Savings Plans ทุกประเภท (โดยเฉพาะ Database Savings Plans) ดูที่ aws.amazon.com/savingsplans/pricing ก่อนเสนอซื้อ
สถาปัตยกรรมที่ลดต่อหน่วย
| เทคนิค | ตัวเลขที่ใช้คุย | ข้อควรระวัง |
|---|---|---|
| Graviton (arm64) | AWS ระบุ price-performance ดีขึ้นได้ถึง ~40% เทียบ x86 รุ่นเทียบเท่า | image/ไลบรารีต้อง build arm64 (multi-arch), ทดสอบ native module |
| Spot | ลดได้ถึง ~90% | ถูกเรียกคืนพร้อมแจ้งล่วงหน้า 2 นาที — ใช้กับงาน stateless/batch/CI, กระจายหลาย instance type, allocation price-capacity-optimized |
| Lambda | ปรับ memory ด้วย Power Tuning, arm64 ถูกกว่า x86 ต่อ GB-s | memory น้อยเกินทำให้ช้าและแพงขึ้น |
| S3 | Intelligent-Tiering สำหรับ access pattern ไม่แน่นอน, lifecycle ไป Glacier | ค่า transition ต่อ object — ไฟล์เล็กมากๆ จำนวนมหาศาลอาจไม่คุ้ม |
| EBS gp2 → gp3 | gp3 ถูกกว่าต่อ GB ราว 20% และตั้ง IOPS แยกได้ | migrate แบบ online ได้ |
| Data transfer | NAT Gateway คิดทั้งรายชั่วโมงและต่อ GB ที่ผ่าน | ใช้ gateway endpoint สำหรับ S3/DynamoDB (ฟรี), วาง traffic ข้าม AZ ให้น้อย |
| Public IPv4 | คิดรายชั่วโมงทุก address (รวมที่ผูกอยู่) ~$3.6/เดือน/IP | ใช้ ALB/CloudFront/IPv6 แทน IP ต่อเครื่อง |
ตัวอย่างคำนวณ NAT: Lambda ใน VPC ดึงไฟล์จาก S3 วันละ 200 GB ผ่าน NAT → ~6 TB/เดือน × ~$0.045/GB ≈ $270/เดือน แค่ค่า processing — เพิ่ม S3 gateway endpoint (ฟรี) → เหลือ ~$0
⚠️ ต้องตรวจสอบ: ราคา NAT Gateway/GB และ public IPv4/ชม. เป็นค่า us-east-1 ณ ปี 2025–2026 ของ ap-southeast-1 อาจสูงกว่า
Tagging และ CUR: ทำให้เงินมีเจ้าของ
- tag บังคับขั้นต่ำ:
Project,Environment,Owner(ทีม),CostCenter— บังคับด้วย IaC default tags + Tag Policies ของ Organizations + SCP deny การสร้างที่ไม่มี tag (สำหรับบริการที่รองรับaws:RequestTag) - tag ใช้ใน billing ได้ต่อเมื่อ activate เป็น cost allocation tag และมีผล ไปข้างหน้าเท่านั้น (ไม่ย้อนหลัง)
- ค่าใช้จ่ายที่ tag ไม่ได้ (data transfer, support, บางส่วนของ CloudWatch) → แบ่งด้วย Cost Categories หรือแยกบัญชี (บท 01)
- CUR 2.0 (ผ่าน Billing → Data Exports) ส่งรายละเอียดระดับ resource/ชั่วโมงเข้า S3 เป็น Parquet → query ด้วย Athena หรือต่อ QuickSight/FOCUS dashboard
- เครื่องมือในตัว: Cost Explorer, Budgets (แจ้งเตือนตาม forecast), Cost Anomaly Detection (ML จับค่าพุ่ง), Cost Optimization Hub (รวมคำแนะนำจาก Compute Optimizer, idle resources, Savings Plans)
Unit economics — ตัวเลขที่ผู้บริหารเข้าใจ: "ค่า cloud ต่อคำสั่งซื้อ" = ค่าบริการของ Project=shop ÷ จำนวน order — บิลโตได้ถ้าธุรกิจโต แต่ต้นทุนต่อหน่วยต้องลดลง
ลองเลย 🧪
⚠️ Cost Explorer API คิดเงินต่อ request (ประมาณ $0.01) — คำสั่งด้านล่างรวมกันไม่กี่สิบ request · ต้องมีสิทธิ์ ce:* (อ่าน) และ billing access (ใช้บัญชี management จะเห็นทั้ง org — profile mgmt = บัญชีเดียวกับ learn ดูตารางใน 6a-01)
aws sso login --profile mgmt
export AWS_PROFILE=mgmt AWS_REGION=us-east-1
START=$(date -u -v-1m +%Y-%m-01 2>/dev/null || date -u -d "$(date +%Y-%m-01) -1 month" +%Y-%m-01)
END=$(date -u +%Y-%m-01)
echo "$START → $END"ทดลอง A — 10 บริการที่แพงที่สุดเดือนที่แล้ว
aws ce get-cost-and-usage --time-period Start=$START,End=$END --granularity MONTHLY \
--metrics UnblendedCost --group-by Type=DIMENSION,Key=SERVICE \
--query "ResultsByTime[0].Groups[].[Keys[0],Metrics.UnblendedCost.Amount]" --output text \
| sort -t$'\t' -k2 -gr | head -10ผลที่ควรเห็น (ตัวอย่าง):
Amazon Relational Database Service 412.33
Amazon Elastic Compute Cloud - Compute 298.10
EC2 - Other 151.87
Amazon CloudWatch 64.02
...→ EC2 - Other มักซ่อน NAT Gateway, EBS, snapshot, data transfer — ขุดต่อด้วย --group-by Type=DIMENSION,Key=USAGE_TYPE และ --filter '{"Dimensions":{"Key":"SERVICE","Values":["EC2 - Other"]}}'
ทดลอง B — ค่าใช้จ่ายต่อบัญชีและต่อ tag
aws ce get-cost-and-usage --time-period Start=$START,End=$END --granularity MONTHLY \
--metrics UnblendedCost --group-by Type=DIMENSION,Key=LINKED_ACCOUNT \
--query "ResultsByTime[0].Groups[].[Keys[0],Metrics.UnblendedCost.Amount]" --output table
aws ce list-cost-allocation-tags --status Inactive --query "CostAllocationTags[].TagKey" --output text
aws ce update-cost-allocation-tags-status --cost-allocation-tags-status TagKey=Project,Status=Active
aws ce get-cost-and-usage --time-period Start=$START,End=$END --granularity MONTHLY \
--metrics UnblendedCost --group-by Type=TAG,Key=Project \
--query "ResultsByTime[0].Groups[].[Keys[0],Metrics.UnblendedCost.Amount]" --output table→ แถว Project$ (ค่าว่าง) = เงินที่ ไม่มีเจ้าของ เป้าหมายคือทำให้ต่ำกว่า 10% · ถ้า activate ไม่ได้ (Tag keys not found) แปลว่ายังไม่มี resource ใดใช้ tag นี้ใน billing — รอให้ tag ปรากฏ (สูงสุดราว 24 ชม.)
ทดลอง C — หาของเสียในบัญชี workload (ต่อ region)
export AWS_PROFILE=dev AWS_REGION=ap-southeast-1
echo "== EBS ที่ไม่ได้ต่อกับเครื่องใด =="
aws ec2 describe-volumes --filters Name=status,Values=available \
--query "Volumes[].[VolumeId,Size,VolumeType,CreateTime]" --output table
echo "== Elastic IP ที่ไม่ได้ผูก =="
aws ec2 describe-addresses --query "Addresses[?AssociationId==null].[PublicIp,AllocationId]" --output table
echo "== NAT Gateway ที่เปิดอยู่ =="
aws ec2 describe-nat-gateways --filter Name=state,Values=available \
--query "NatGateways[].[NatGatewayId,VpcId,SubnetId]" --output table
echo "== gp2 ที่ควรย้ายเป็น gp3 =="
aws ec2 describe-volumes --filters Name=volume-type,Values=gp2 --query "Volumes[].[VolumeId,Size]" --output table
echo "== log group ไม่มี retention =="
aws logs describe-log-groups --query "logGroups[?!retentionInDays].logGroupName" --output textแต่ละรายการ: ตัดสินใจ ลบ / ย้าย / เก็บพร้อมเหตุผล — ย้าย gp2 → gp3 แบบ online: aws ec2 modify-volume --volume-id [vol-...] --volume-type gp3
ทดลอง D — คำแนะนำ Savings Plans และ rightsizing
export AWS_PROFILE=mgmt AWS_REGION=us-east-1
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 \
--query "SavingsPlansPurchaseRecommendation.SavingsPlansPurchaseRecommendationSummary.[HourlyCommitmentToPurchase,EstimatedMonthlySavingsAmount,EstimatedSavingsPercentage]" \
--output text
aws compute-optimizer get-enrollment-status --query status --output text
# ถ้าเป็น Inactive: aws compute-optimizer update-enrollment-status --status Active (ฟรีระดับพื้นฐาน รอข้อมูลราว 12–24 ชม.)
aws compute-optimizer get-ec2-instance-recommendations --region ap-southeast-1 \
--query "instanceRecommendations[].[instanceArn,finding,currentInstanceType,recommendationOptions[0].instanceType]" --output table→ ถ้า recommendation ว่าง = ใช้น้อยเกินจะคุ้ม หรือข้อมูลยังไม่พอ · อย่าซื้อตามตัวเลขทันที — หักส่วนที่กำลังจะย้ายไป Graviton/Spot/serverless ก่อน
ทดลอง E — Budget แจ้งเตือนตาม forecast (budget ไม่กี่ตัวแรกไม่คิดเงิน)
ACCOUNT=$(aws sts get-caller-identity --query Account --output text)
aws budgets create-budget --account-id "$ACCOUNT" \
--budget '{"BudgetName":"monthly-total","BudgetLimit":{"Amount":"100","Unit":"USD"},"TimeUnit":"MONTHLY","BudgetType":"COST"}' \
--notifications-with-subscribers '[{"Notification":{"NotificationType":"FORECASTED","ComparisonOperator":"GREATER_THAN","Threshold":80,"ThresholdType":"PERCENTAGE"},"Subscribers":[{"SubscriptionType":"EMAIL","Address":"[[email protected]]"}]}]'
aws budgets describe-budgets --account-id "$ACCOUNT" --query "Budgets[].[BudgetName,BudgetLimit.Amount]" --output tableทดลอง F (ถ้ามี CUR 2.0 ใน Athena แล้ว) — top resource ตาม tag
SELECT resource_tags['user_project'] AS project,
line_item_product_code AS service,
line_item_resource_id AS resource,
ROUND(SUM(line_item_unblended_cost), 2) AS cost
FROM cur2.data
WHERE billing_period = '[2026-09]'
GROUP BY 1, 2, 3
ORDER BY cost DESC
LIMIT 20;⚠️ ต้องตรวจสอบ: ชื่อ database/table ขึ้นกับการตั้ง Data Export ของคุณ · CUR 2.0 เก็บ tag ในคอลัมน์ map
resource_tagsเฉพาะ tag ที่ activate เป็น cost allocation tag แล้ว และ key ถูก normalize จากชื่อใน billing: tag ที่เราตั้งเอง (user:Project) →user_project,CostCenter→user_cost_center(ใส่_หน้าตัวพิมพ์ใหญ่ แปลงเป็นตัวเล็ก อักขระพิเศษเป็น_) — ไม่แน่ใจให้SELECT map_keys(resource_tags) FROM ... LIMIT 10ดูก่อน
เก็บกวาด
aws budgets delete-budget --account-id "$ACCOUNT" --budget-name monthly-total # ถ้าไม่ต้องการเก็บไว้ถ้าพัง: AccessDeniedException ใน ce → ยังไม่เปิด IAM access to billing หรือ permission set ไม่มี ce:Get* · DataUnavailableException → บัญชีใหม่/เพิ่งเปิด Cost Explorer รอ 24 ชม. · date: illegal option → ใช้รูปแบบ date ของ OS อื่น บรรทัด START มีทั้งสองแบบแล้ว ตรวจว่าได้วันที่ถูก
กับดักที่เจอบ่อย
| อาการ | สาเหตุ / แก้ |
|---|---|
| ซื้อ Savings Plans แล้วใช้ไม่เต็ม (utilization < 100%) | ผูกเกิน baseline หรือย้ายไป Graviton/serverless ทีหลัง — ซื้อทีละน้อยหลัง rightsizing |
EC2 - Other แพงลึกลับ |
NAT data processing, EBS snapshot, cross-AZ transfer — group by USAGE_TYPE |
| ค่า NAT สูงกว่าค่า compute | traffic ไป S3/DynamoDB ผ่าน NAT — เพิ่ม gateway endpoint |
| เปิด Spot กับ DB/stateful แล้วข้อมูลหาย | Spot ถูกเรียกคืนได้ทุกเมื่อ — ใช้กับ stateless/batch และรองรับ 2-minute notice |
| tag ครบแล้วแต่รายงานเดือนก่อนยังว่าง | cost allocation tag ไม่ย้อนหลัง — activate เร็วที่สุด |
| ลดค่าใช้จ่ายแล้ว SLO พัง | ลด replica/AZ ใน prod — ลดของเสียก่อน อย่าตัด redundancy ที่ซื้อ reliability |
สรุปจำง่าย
มองเห็น → ทิ้งของเสีย → rightsizing → สถาปัตยกรรม (Graviton, Spot, endpoint, storage class) → ค่อยผูก Savings Plans ไม่เกิน baseline — ทุกบาทต้องมี tag เจ้าของ activate ทันที — EC2-Other คือที่ซ่อน NAT/EBS — วัดเป็นต้นทุนต่อหน่วยธุรกิจ