VPC Flow Logs and Traffic Mirroring
VPC Flow Logs at the VPC, subnet and ENI level, their record format, troubleshooting security groups and NACLs with them, common architectures, and VPC Traffic Mirroring.
VPC Flow Logs
VPC Flow Logs capture information about IP traffic going into the interfaces:
- VPC flow logs;
- subnet flow logs;
- elastic network interface (ENI) flow logs.
They help to monitor and troubleshoot connectivity issues.
- Flow log data can go to S3, CloudWatch Logs and Data Firehose.
- They capture network information from AWS managed interfaces too: ELB, RDS, ElastiCache, Redshift, WorkSpaces, NAT gateway, Transit Gateway…
- They record metadata (who talked to whom, on which port, accepted or rejected), not the packet contents.
Flow log syntax
2 123456789010 eni-1235b8ca123456789 172.31.16.139 172.31.16.21 20641 22 6 20 4249 1418530010 1418530070 ACCEPT OK
2 123456789010 eni-1235b8ca123456789 172.31.9.69 172.31.9.12 49761 3389 6 20 4249 1418530010 1418530070 REJECT OKThe fields: version, account-id, interface-id, srcaddr, dstaddr, srcport, dstport, protocol, packets, bytes, start, end, action, log-status.
- srcaddr and dstaddr: help identify problematic IPs.
- srcport and dstport: help identify problematic ports.
- action: success or failure of the request because of a security group or NACL.
- Can be used for analytics on usage patterns, or malicious behaviour.
- Query VPC Flow Logs with Athena on S3, or CloudWatch Logs Insights.
Troubleshooting security groups and NACLs
Look at the action field:
- Incoming requests:
- inbound REJECT → NACL or SG;
- inbound ACCEPT, outbound REJECT → NACL (a security group would have allowed the response, because it's stateful).
- Outgoing requests:
- outbound REJECT → NACL or SG;
- outbound ACCEPT, inbound REJECT → NACL.
Architectures
- CloudWatch Logs → Contributor Insights → the top-10 IP addresses.
- CloudWatch Logs → metric filter (SSH, RDP…) → CloudWatch alarm → SNS alert.
- S3 bucket → Athena → QuickSight for analysis and dashboards.
CloudWatch permissions: the IAM service role used by VPC Flow Logs must have permission to publish to CloudWatch Logs: logs:CreateLogGroup, logs:CreateLogStream, logs:PutLogEvents (and DescribeLogGroups, DescribeLogStreams).
Traffic Mirroring
Traffic Mirroring can capture and inspect network traffic in a VPC.
- Routes the traffic to security appliances that the customer manages.
- Capture the traffic:
- from (source): ENIs;
- to (target): an ENI, a Network Load Balancer, or a Gateway Load Balancer (with a UDP listener).
- Capture all packets, or only the packets of interest (filters), and optionally truncate packets.
- Source and target can be in the same VPC or different VPCs (VPC peering).
- Use cases: content inspection, threat monitoring, troubleshooting…
Flow Logs give metadata; Traffic Mirroring gives a copy of the packets.
Exam tips
- "Troubleshoot why connections are rejected", "which IPs talk to my instance" → VPC Flow Logs.
- "Inbound ACCEPT but outbound REJECT" → NACL (stateless) problem.
- "Analyse flow logs with SQL" → S3 + Athena (or CloudWatch Logs Insights).
- "Inspect packet contents with an IDS appliance" → Traffic Mirroring.
Common traps
- "Flow Logs show the packet payload." Only metadata; for packets, use Traffic Mirroring.
- "Flow Logs to CloudWatch work without permissions." They need an IAM role that can write logs.
Check yourself
Flow logs to S3 cost little, but need traffic to be meaningful, so instead:
The NACL: it allows inbound port 22 but its outbound rules don't allow the ephemeral port range back to the client. The security group would have allowed the response automatically.
AWS documentation
NACLs vs security groups
Network ACLs as stateless subnet firewalls, rule numbers and order, the default NACL, ephemeral ports, and how NACLs differ from security groups.
AWS Network Firewall
The network protection options on AWS, and AWS Network Firewall for layer 3 to layer 7 protection of a whole VPC with stateful rules, domain filtering and intrusion prevention.