VPC Flow Logs
VPC Flow Logs ใช้สำหรับบันทึกข้อมูล IP Traffic ที่ไหลผ่าน Network Interfaces ภายใน VPC เพื่อใช้ในการ Monitoring, Troubleshooting และ Security Analysis
ภาพรวม
- เก็บข้อมูลของ IP Traffic ทุกชนิด ที่เข้า-ออก Network Interfaces
- สามารถสร้าง Flow Logs ได้ในหลายระดับ:
- VPC Level - เก็บ traffic ทั้งหมดภายใน VPC
- Subnet Level - เก็บ traffic เฉพาะ Subnet ที่กำหนด
- ENI (Elastic Network Interface) Level - เก็บ traffic เฉพาะ ENI ที่กำหนด
- ครอบคลุม traffic จาก AWS Managed Services เช่น ELB, ElastiCache, RDS, Aurora, Redshift
ข้อมูลที่บันทึก
Flow Log จะบันทึกข้อมูลสำคัญต่อไปนี้:
- Source IP / Destination IP - IP ต้นทางและปลายทาง
- Source Port / Destination Port - พอร์ตต้นทางและปลายทาง
- Protocol - โปรโตคอลที่ใช้ (TCP, UDP, ICMP)
- Packets / Bytes - จำนวน packets และขนาดข้อมูล
- Action - ACCEPT หรือ REJECT
- Log Status - สถานะการบันทึก (OK, NODATA, SKIPDATA)
ปลายทางสำหรับเก็บ Flow Logs
- Amazon S3 - เหมาะสำหรับเก็บระยะยาวและวิเคราะห์ด้วย Amazon Athena
- CloudWatch Logs - เหมาะสำหรับ real-time monitoring และสร้าง Metric Filters / Alarms
- Kinesis Data Firehose - เหมาะสำหรับ streaming ไปยัง third-party analytics tools
การวิเคราะห์ Flow Logs
ใช้ Amazon Athena
- Query Flow Logs ที่เก็บใน S3 ด้วย SQL
- เหมาะสำหรับวิเคราะห์ traffic patterns, ค้นหา anomalies, หรือตรวจสอบ rejected connections
- ตัวอย่าง: ค้นหา IP ที่ถูก reject บ่อยที่สุด
ใช้ CloudWatch Logs Insights
- Query logs แบบ real-time
- สร้าง Dashboard สำหรับ monitoring
- ตั้ง Alarm เมื่อมี rejected traffic จำนวนมากผิดปกติ
Use Cases
- Troubleshooting - วิเคราะห์ว่าทำไม traffic ถึงไม่สามารถเข้าถึง Instance ได้ (เช่น NACL หรือ SG block)
- Security Monitoring - ตรวจจับ traffic ที่น่าสงสัย เช่น port scanning, brute force attempts
- Compliance - บันทึก traffic logs เพื่อตอบสนองข้อกำหนดด้าน compliance
- Cost Analysis - วิเคราะห์ traffic patterns เพื่อ optimize ค่าใช้จ่าย data transfer
ข้อควรรู้
- Flow Logs ไม่กระทบ network throughput หรือ latency ของ traffic
- ไม่สามารถแก้ไข Flow Log หลังจากสร้างแล้ว (ต้องลบแล้วสร้างใหม่)
- ไม่บันทึก traffic บางประเภท เช่น:
- Traffic ไปยัง Amazon DNS Server
- Traffic สำหรับ Windows License Activation
- Traffic จาก Instance Metadata (169.254.169.254)
- DHCP Traffic