14.2 Network Traffic Analysis: VPC Flow Logs & Log Analytics
Key Takeaways
- VPC Flow Logs capture IP network flow metadata without inspecting packet payloads, publishing at the VPC, subnet, or ENI level to Amazon CloudWatch Logs, Amazon S3, or Amazon Kinesis Data Firehose.
- Flow log filters specify whether to record accepted connections (ACCEPT), rejected security policy drops (REJECT), or all traffic (ALL), excluding internal AWS service traffic such as Route 53 link-local DNS and instance metadata.
- Custom flow log formats extend beyond standard 5-tuple fields to capture tcp-flags, pkt-srcaddr, and pkt-dstaddr, enabling engineers to analyze TCP bitmasks (SYN flag 2, SYN-ACK flag 18, RST flag 4) and trace original IPs through NAT Gateways.
- CloudWatch Logs Insights provides interactive querying to aggregate bandwidth consumption ("top talkers"), unmask malicious port scanning, and isolate asymmetric return traffic drops caused by stateless NACLs.
- End-to-end network observability requires correlating VPC Flow Logs with Application Load Balancer access logs, CloudFront access logs, and AWS WAF web ACL traffic logs to diagnose application latency and security blocks.
14.2 Network Traffic Analysis: VPC Flow Logs & Log Analytics
CloudOps Blueprint Focus: Packet payload inspection is rarely viable in high-throughput cloud environments. The AWS Certified CloudOps Engineer – Associate (SOA-C03) exam tests your ability to configure Amazon VPC Flow Logs, interpret default and custom log formats, decode TCP flags, run targeted CloudWatch Logs Insights queries, and correlate network flows with Application Load Balancer and AWS WAF telemetry.
VPC Flow Logs Architecture & Capture Scope
Amazon VPC Flow Logs captures IP traffic flow metadata entering and leaving network interfaces across an Amazon VPC. Operating out-of-band at the hypervisor level, Flow Logs impose zero latency overhead and zero compute impact on running workloads.
Capture Levels & Publishing Destinations
Flow logs can be provisioned at three architectural scopes:
- VPC Level: Monitors all current and future ENIs across all subnets in the VPC.
- Subnet Level: Captures traffic across all ENIs within a specific subnet.
- Network Interface (ENI) Level: Surgically targets an individual ENI for focused troubleshooting.
| Publish Destination | Operational Characteristics | Target Use Cases |
|---|---|---|
| Amazon CloudWatch Logs | Near real-time streaming; CloudWatch metric filters and alarms; interactive querying via Logs Insights. | Operational troubleshooting, security alarming, rapid incident response. |
| Amazon S3 | Cost-effective storage; S3 Glacier lifecycle archiving; SQL analysis via Amazon Athena. | Compliance data lakes, long-term auditing, forensic retention. |
| Amazon Kinesis Data Firehose | Managed streaming delivery to external destinations; real-time Lambda transformations. | Ingestion into third-party SIEMs (Splunk, Datadog) or OpenSearch. |
Traffic Filters & Non-Captured Traffic
Engineers select one of three traffic filters:
ALL: Records both permitted and blocked flows; required for complete visibility.ACCEPT: Records only traffic permitted by Security Groups and NACLs; used for capacity planning and baselining.REJECT: Records only traffic blocked by Security Groups or NACLs; optimizes cost for threat hunting.
[!IMPORTANT] Non-Captured Traffic: Flow Logs do not record traffic to the Amazon DNS Route 53 Resolver (VPC base CIDR + 2, e.g.,
10.0.0.2), EC2 Instance Metadata Service (169.254.169.254), Amazon Time Sync (169.254.169.123), DHCP client traffic, or hypervisor licensing communication.
Log Formats & Extended Telemetry Fields
Flow logs aggregate packets over 10-minute intervals (or 1-minute intervals for accelerated troubleshooting).
Default vs. Custom Formats
The default format outputs 14 fields:
<version> <account-id> <interface-id> <srcaddr> <dstaddr> <srcport> <dstport> <protocol> <packets> <bytes> <start> <end> <action> <log-status>
Standard protocol numbers include 6 (TCP), 17 (UDP), and 1 (ICMP).
To troubleshoot complex topologies, engineers deploy a Custom Log Format incorporating extended attributes:
tcp-flags: Bitmask identifying TCP control flags observed during the flow window.pkt-srcaddr&pkt-dstaddr: Captures the original packet source and destination IP addresses before Network Address Translation (NAT) through a NAT Gateway.flow-direction: Identifies whether the flow wasingressoregressrelative to the interface.traffic-path: Shows the routing path (e.g., Internet Gateway, Transit Gateway, or Peering).
Decoding TCP Flag Bitmasks
TCP flags reveal connection handshake stages:
2(SYN): Connection initiation. Repeatedtcp-flags = 2withaction = REJECTindicates blocked connection attempts or port scanning.18(SYN-ACK = 16 + 2): Handshake acknowledged; confirms bidirectional connectivity.4(RST): Connection reset; indicates abnormal session termination by a host or firewall.1(FIN) /16(ACK): Standard graceful connection teardown.
CloudWatch Logs Insights Queries for Network Troubleshooting
Amazon CloudWatch Logs Insights provides an interactive engine to scan millions of flow records rapidly.
1. Identifying Port Scanning & Reconnaissance
To identify hostile internal or external scanning activity:
filter action = "REJECT"
| stats count(*) as DropCount by srcaddr, dstport, protocol
| sort DropCount desc
| limit 20
A high DropCount on ports 22 (SSH), 3389 (RDP), or 445 (SMB) highlights brute-force or scanning attempts.
2. Finding Top Talkers & Bandwidth Consumers
To isolate instances driving high cross-AZ or NAT Gateway data transfer charges:
filter action = "ACCEPT"
| stats sum(bytes) as TotalBytes, sum(packets) as TotalPackets by srcaddr, dstaddr
| sort TotalBytes desc
| limit 10
3. Diagnosing Stateless NACL Return Traffic Drops
When an application establishes outbound connections that fail to receive responses:
filter (srcaddr = "10.0.1.25" and dstaddr = "198.51.100.10") or
(srcaddr = "198.51.100.10" and dstaddr = "10.0.1.25")
| fields @timestamp, srcaddr, dstaddr, srcport, dstport, protocol, action, bytes
| sort @timestamp desc
If the outbound request (10.0.1.25:52140 -> 198.51.100.10:443) is ACCEPTed, but the return packet (198.51.100.10:443 -> 10.0.1.25:52140) displays REJECT, a stateless NACL is dropping the response on ephemeral port 52140.
Correlating Multi-Layer Network Telemetry
Isolating application issues requires correlating Layer 3/4 flow logs with Layer 7 load balancer and security telemetry.
Elastic Load Balancing (ELB) Access Logs
ELB access logs provide three critical timing metrics:
request_processing_time: Latency from client request reception to dispatch to backend.target_processing_time: Time spent by backend EC2/container instances processing the request before sending headers. High values indicate application code or database query latency.response_processing_time: Time taken to transmit the response to the client.- Status Code Discrepancies: If
elb_status_codeis504andtarget_status_codeis-, the backend target timed out before responding.
AWS WAF Web ACL Logs & CloudFront Logs
- AWS WAF Logs: Capture the
terminatingRuleIdand action (BLOCK,ALLOW,COUNT). When users encounter HTTP 403 errors, WAF logs confirm whether managed rules (e.g., SQLi or rate-limiting) blocked the client IP. - CloudFront Access Logs: Record edge cache hits/misses, origin latency, and TLS protocol negotiation, pinpointing whether latency occurs at the edge or origin.
A security engineer suspects that an Amazon EC2 instance in a private subnet is subject to internal port scanning from another compromised resource within the VPC. The engineer needs to write a CloudWatch Logs Insights query against the VPC Flow Logs log group to identify the internal IP addresses generating the largest volume of dropped connection attempts and the specific destination ports targeted. Which query syntax accomplishes this?
An application tier running on EC2 instances behind an Application Load Balancer connects to external third-party payment gateways via an AWS NAT Gateway. Developers report intermittent connection timeouts. The CloudOps engineer configures VPC Flow Logs on the NAT Gateway's elastic network interface (ENI) using a custom log format. Which flow log fields are essential to distinguish the original internal EC2 client IP address from the NAT Gateway's public IP and evaluate whether the TCP connection handshake completed?
An operations team notices that requests to their web application occasionally fail with HTTP 504 Gateway Timeout errors. The application architecture consists of an Application Load Balancer (ALB) routing traffic to a fleet of Amazon EC2 instances in an Auto Scaling group. To pinpoint whether the delay originates in the ALB network infrastructure, backend instance processing, or client network disconnection, which telemetry source and metrics should the team analyze first?