VPC Flow Logs

A record of the IP traffic metadata on your network interfaces — who talked to whom, on which ports, how much, and whether it was accepted or rejected. Not the packet contents, just the envelope. It is the first tool you reach for to answer "is something blocking this traffic?".

Một bản ghi metadata của traffic IP trên các network interface của bạn — ai nói chuyện với ai, cổng nào, bao nhiêu, và bị chấp nhận hay từ chối. Không phải nội dung gói tin, chỉ là cái phong bì. Đây là công cụ đầu tiên để trả lời "có thứ gì đang chặn traffic này không?".

Two things to fix in memory: it captures metadata, never payload (payload needs Traffic Mirroring), and the action field is the Security Group / NACL decision — which is exactly what makes it a connectivity-troubleshooting tool.

Hai điều cần khắc vào đầu: nó ghi metadata, không bao giờ payload (muốn payload thì dùng Traffic Mirroring), và trường action là quyết định của Security Group / NACL — chính điều đó khiến nó thành công cụ gỡ lỗi kết nối.

Flow Logs answer this… / reach for something else for that…Flow Logs trả lời được… / thứ khác cho…

Use Flow LogsDùng Flow Logs

  • "Is traffic being blocked?" — the ACCEPT/REJECT action pins it on a Security Group or NACL."Traffic có bị chặn không?" — action ACCEPT/REJECT chỉ đích danh Security Group hay NACL.
  • Forensics / audit: who connected to what, when, and how much data moved.Điều tra / kiểm toán: ai kết nối tới đâu, khi nào, chuyển bao nhiêu dữ liệu.
  • Traffic analytics — usage patterns or malicious behaviour — by querying with Athena or Logs Insights.Phân tích traffic — mẫu sử dụng hay hành vi độc hại — bằng cách query với Athena hoặc Logs Insights.
  • Monitoring traffic on managed endpoints too — NAT Gateway, ELB, Transit Gateway.Theo dõi traffic cả trên endpoint được quản lý — NAT Gateway, ELB, Transit Gateway.

Reach for something elseChuyển sang thứ khác

  • You need the packet contents / payload (deep inspection, IDS) → VPC Traffic Mirroring. Flow Logs are metadata only.Cần nội dung gói tin / payload (soi sâu, IDS) → VPC Traffic Mirroring. Flow Logs chỉ là metadata.
  • Application-level metrics (latency, error rates) → CloudWatch metrics, not flow logs.Chỉ số ở tầng ứng dụng (độ trễ, tỉ lệ lỗi) → chỉ số CloudWatch, không phải flow logs.
  • API call history (who called which AWS API) → CloudTrail, a different log.Lịch sử gọi API (ai gọi API AWS nào) → CloudTrail, một loại log khác.
  • Traffic that flow logs don't capture (metadata service, Amazon DNS) simply won't appear — don't debug with it.Traffic mà flow logs không ghi (metadata service, Amazon DNS) sẽ không xuất hiện — đừng dùng nó để debug.

Three scopes — VPC, Subnet, ENIBa phạm vi — VPC, Subnet, ENI

You attach a flow log at one of three levels, and it covers every network interface inside that level. A VPC flow log covers all ENIs in the VPC; a Subnet flow log all ENIs in that subnet; an ENI flow log just that one interface. Bạn gắn flow log ở một trong ba cấp, và nó phủ mọi network interface bên trong cấp đó. Flow log ở cấp VPC phủ mọi ENI trong VPC; cấp Subnet phủ mọi ENI trong subnet đó; cấp ENI chỉ đúng một interface.

The three scopes of a VPC flow log, drawn as nested boxes. The outermost box is the VPC — a VPC flow log covers every network interface in the VPC. Inside it is a subnet — a subnet flow log covers every interface in that subnet. Inside that is a single ENI — an ENI flow log covers just that one network interface. You choose the scope; the log captures everything inside it. pick a level — the log covers every interface inside it VPC Flow Log → every ENI in the VPC Subnet Flow Log → every ENI in the subnet ENI Flow Log → one network interface eni-1235b8ca123456789 smaller scope = fewer interfaces logged · same record format at every level

The nesting is the whole model: a VPC log is a subnet log is an ENI log, just wider. Same fields at every level — you're only choosing how many interfaces to include.

Cái lồng nhau chính là toàn bộ mô hình: log VPC cũng là log subnet cũng là log ENI, chỉ rộng hơn. Cùng bộ trường ở mọi cấp — bạn chỉ đang chọn bao nhiêu interface được đưa vào.

The record — the fields, and what each answersBản ghi — các trường, và mỗi trường trả lời gì

One line per flow, over a capture window. The default format is a fixed sequence of fields; the ones that matter for troubleshooting are the 5-tuple (source/dest IP, source/dest port, protocol) and the action. Một dòng cho mỗi flow, trong một cửa sổ ghi. Định dạng mặc định là một chuỗi trường cố định; những trường quan trọng khi gỡ lỗi là 5-tuple (IP nguồn/đích, cổng nguồn/đích, protocol) và action.

The default VPC flow log record broken into its fields across two rows. Row one: version 2, account-id ending 6789010, interface-id eni-1235b8ca...789, srcaddr 172.31.16.139, dstaddr 172.31.16.21, srcport 20641, dstport 22. Row two: protocol 6 which is TCP, packets 20, bytes 4249, start 1418530010, end 1418530070, action ACCEPT, log-status OK. Notes explain that srcaddr and dstaddr identify the IPs, srcport and dstport identify the ports, protocol 6 is TCP 17 is UDP 1 is ICMP, action is the Security Group or NACL decision of ACCEPT or REJECT, and the five-tuple of source and destination IP, source and destination port, and protocol identifies one flow. one flow, one line — the default fields (v2) version 2 account-id …6789010 interface-id eni-1235b8ca…789 srcaddr 172.31.16.139 dstaddr 172.31.16.21 srcport 20641 dstport 22 protocol 6 (TCP) packets 20 bytes 4249 start 1418530010 end 1418530070 action ACCEPT log-status OK srcaddr + dstaddr → which IPs are talking (find a problematic host) srcport + dstport → which ports (here dstport 22 = SSH) protocol → 6 = TCP · 17 = UDP · 1 = ICMP action → ACCEPT or REJECT = the Security Group / NACL decision the 5-tuple {src IP, dst IP, src port, dst port, protocol} = one flow a second example line ending in REJECT OK would mean that flow was denied log-status: OK = data normal · NODATA = no traffic · SKIPDATA = some records dropped

Two fields do most of the work in an exam: dstport tells you what was being attempted (22 = SSH, 3389 = RDP, 443 = HTTPS), and action tells you whether the SG/NACL let it through. A REJECT on the port you expected is your answer.

Hai trường làm phần lớn công việc trong đề thi: dstport cho biết đang thử làm gì (22 = SSH, 3389 = RDP, 443 = HTTPS), và action cho biết SG/NACL có cho qua không. Một REJECT ở đúng cổng bạn mong đợi chính là câu trả lời.

Destinations — where the logs goĐích đến — log chảy về đâu

Three targets, and the choice is really "how will I read it": S3 for cheap storage you query with Athena; CloudWatch Logs for interactive Logs Insights queries and alarms; Kinesis Data Firehose to stream on to OpenSearch, Splunk, or a data lake. Ba đích, và lựa chọn thật ra là "tôi sẽ đọc nó bằng cách nào": S3 để lưu rẻ rồi query bằng Athena; CloudWatch Logs để query tương tác bằng Logs Insights và đặt alarm; Kinesis Data Firehose để đẩy tiếp tới OpenSearch, Splunk, hoặc data lake.

The three destinations for VPC flow logs. From a VPC Flow Logs source on the left, three arrows go to: Amazon S3, queried with Athena; CloudWatch Logs, queried with Logs Insights; and Kinesis Data Firehose, which streams onward to OpenSearch, Splunk, or a data lake. the destination decides how you'll read the logs VPC Flow Logs source Amazon S3 cheap storage → query with Athena (SQL) CloudWatch Logs interactive Logs Insights queries + alarms Kinesis Data Firehose stream onward → OpenSearch, Splunk, data lake S3 + Athena for ad-hoc SQL · CloudWatch Logs Insights for quick interactive digs

Pick by the reading tool, not the storage. "Query the flow logs with SQL" is the tell for S3 + Athena; "interactive investigation / alarm" is CloudWatch Logs Insights; "into our SIEM" is Firehose.

Chọn theo công cụ đọc, không theo chỗ lưu. "Query flow logs bằng SQL" là dấu hiệu của S3 + Athena; "điều tra tương tác / alarm" là CloudWatch Logs Insights; "đưa vào SIEM" là Firehose.

Captures managed interfaces tooGhi cả interface được quản lý Flow logs aren't limited to your EC2 ENIs — they capture the network interfaces of AWS-managed services as well: ELB, RDS, ElastiCache, Redshift, WorkSpaces, NAT Gateway, and Transit Gateway. That is how you see traffic through a NAT Gateway or across a Transit Gateway that you don't otherwise control the ENI for. Flow logs không chỉ giới hạn ở ENI của EC2 — nó ghi cả network interface của service do AWS quản lý: ELB, RDS, ElastiCache, Redshift, WorkSpaces, NAT Gateway, và Transit Gateway. Đó là cách bạn nhìn thấy traffic qua NAT Gateway hay xuyên Transit Gateway mà bình thường bạn không nắm ENI của chúng.

Things that catch you outNhững chỗ dễ sập bẫy

  • Metadata, not payload. Flow logs never contain packet contents. If a question wants the actual bytes (deep packet inspection, IDS/IPS), the answer is VPC Traffic Mirroring. Metadata, không phải payload. Flow logs không bao giờ chứa nội dung gói tin. Nếu đề muốn chính các byte (soi gói sâu, IDS/IPS) thì đáp án là VPC Traffic Mirroring.
  • Not all traffic is captured. Excluded flows include the instance metadata service (169.254.169.254), Amazon-provided DNS, DHCP, and Windows license activation. If you're chasing one of those, flow logs won't help. Không phải traffic nào cũng được ghi. Các flow bị loại gồm instance metadata service (169.254.169.254), DNS do Amazon cấp, DHCP, và kích hoạt license Windows. Nếu đang truy mấy cái đó thì flow logs không giúp được.
  • ACCEPT ≠ "the app worked". ACCEPT means the SG/NACL let the packet through, not that anything answered. And a return-path REJECT can trace to a stateless NACL even when the stateful SG was fine. ACCEPT ≠ "ứng dụng chạy". ACCEPT nghĩa là SG/NACL cho gói qua, không phải có ai trả lời. Và một REJECT ở đường về có thể do NACL không lưu trạng thái dù SG (có trạng thái) vẫn ổn.
  • It's aggregated over a window, not per-packet real time. Records cover a capture window (default ~10 min, or 1 min), so don't expect instant, packet-by-packet visibility. Được gộp theo cửa sổ thời gian, không phải real-time từng gói. Bản ghi phủ một cửa sổ ghi (mặc định ~10 phút, hoặc 1 phút), nên đừng mong thấy tức thời theo từng gói.
  • Query, don't scroll. At any real scale you read flow logs by querying — Athena over S3, or CloudWatch Logs Insights — not by eyeballing raw records. Query, đừng cuộn tay. Ở quy mô thật, bạn đọc flow logs bằng cách query — Athena trên S3, hoặc CloudWatch Logs Insights — chứ không phải dò từng bản ghi thô.

Exam reflexesPhản xạ khi thi

The question says…Đề nói… AnswerĐáp án
"Find out if a Security Group / NACL is blocking traffic""Tìm xem Security Group / NACL có chặn traffic không" VPC Flow Logs — read the action field (ACCEPT/REJECT)VPC Flow Logs — đọc trường action (ACCEPT/REJECT)
"Capture the packet contents / payload for inspection""Bắt nội dung gói tin / payload để soi" VPC Traffic Mirroring — not Flow LogsVPC Traffic Mirroring — không phải Flow Logs
"Query traffic logs with SQL""Query log traffic bằng SQL" Flow logs to S3, query with AthenaFlow logs vào S3, query bằng Athena
"Interactively investigate / alarm on traffic""Điều tra tương tác / đặt alarm trên traffic" Flow logs to CloudWatch Logs → Logs InsightsFlow logs vào CloudWatch Logs → Logs Insights
"Stream flow logs into a SIEM / OpenSearch / Splunk""Đẩy flow logs vào SIEM / OpenSearch / Splunk" Kinesis Data FirehoseKinesis Data Firehose
"See traffic through a NAT Gateway / Transit Gateway / ELB""Xem traffic qua NAT Gateway / Transit Gateway / ELB" Flow Logs — they cover AWS-managed ENIs tooFlow Logs — ghi cả ENI do AWS quản lý
"Detect malicious IPs / traffic patterns""Phát hiện IP độc hại / mẫu traffic bất thường" Flow Logs + analytics (Athena / Logs Insights) — or feed GuardDutyFlow Logs + phân tích (Athena / Logs Insights) — hoặc đưa vào GuardDuty