Skip to Content
Asterrr's Handbook
3 · Infrastructure security

VPC Flow Logs and Traffic Mirroring

Metadata logging versus full packet capture in a VPC, what flow logs miss, and how to tell NACL denies from security group denies.

Exam tasks: 3.3 (troubleshooting network access with VPC Flow Logs)

The decision: do you need metadata about accepted and rejected flows, or the packet contents, and which layer dropped the traffic?

VPC Flow Logs record metadata about IP flows (who, which ports, how many bytes, accepted or rejected). Traffic Mirroring copies the actual packets to an inspection appliance. Flow logs answer "what happened". Mirroring answers "what was inside".

ENI, subnet orVPCFlow logCloudWatch LogsS3 bucketData Firehose
Flow logs are collected out of band, with no effect on throughput or latency, and published to one of three destinations.

Flow Logs versus Traffic Mirroring

ItemVPC Flow LogsTraffic Mirroring
CapturesMetadata. Addresses, ports, protocol, packets, bytes, ACCEPT or REJECTFull packets, optionally truncated
Attach toVPC, subnet or network interfaceSource network interface (type interface)
OutputCloudWatch Logs, S3, Data FirehoseTarget ENI, Network Load Balancer, or Gateway Load Balancer endpoint
UseTroubleshooting, audit, anomaly detectionContent inspection, threat monitoring, forensics and attack reverse engineering
Cost shapeVended log ingestion and archive chargesCharged per active session hour, even if the source is stopped

Flow log concepts to know.

  • Choose the traffic filter at creation. Accepted, rejected or all.
  • Works for interfaces owned by other services too, such as ELB, RDS, ElastiCache, Redshift, WorkSpaces, NAT gateways and transit gateways. Create these through the EC2 console or API.
  • You cannot change a flow log after creation. Delete and recreate it to change the format or IAM role.
  • Deleting a flow log does not delete the data already published.
  • Records can be delayed. Flow logs are not real time.
  • On Nitro instances the aggregation interval is always 1 minute or less.
  • Use the pkt-srcaddr and pkt-dstaddr fields to see original addresses behind NAT gateways or secondary IPs.

Traffic that is not logged

Not captured
Instance traffic to the Amazon DNS server (queries to your own DNS server are logged)
Instance metadata at 169.254.169.254 and Time Sync at 169.254.169.123
DHCP traffic
Windows license activation
Traffic to the default VPC router's reserved address
ARP traffic
Mirrored source traffic (only the mirror target traffic shows)

Is it the NACL or the security group

Ping from a client to an instance whose security group allows inbound ICMP.

Flow log showsMeaning
ACCEPT (request) and ACCEPT (reply)Both layers allow the traffic
ACCEPT (request) then REJECT (reply)NACL allows the request but denies the reply. Security groups are stateful so they would have allowed it
A single REJECTDenied inbound. The security group (or NACL inbound) blocked the request. The traffic never reached the instance

Exam signal

"Centralize network logs from every VPC for later Athena queries" means flow logs to an S3 bucket. "Need packet payloads to reverse engineer an attack" means Traffic Mirroring.

Exam trap

Flow logs never contain payloads, and DNS queries to the Amazon resolver are not in them. Use Route 53 Resolver query logs for DNS visibility.

Records and destinations

  • Capture at VPC, subnet, ENI or transit gateway level. Publish to CloudWatch Logs, S3 (query with Athena) or Data Firehose.
  • A default record has source and destination IP and port, protocol, packets, bytes and action (ACCEPT or REJECT). Add custom fields such as tcp-flags, flow-direction and traffic-path.
  • See Security Lake for querying logs at scale.

Scenarios

Scenario
An instance in a private subnet can't reach an internal API on port 8443 in another subnet of the same VPC. VPC Flow Logs on the API's network interface show the inbound request as ACCEPT and the outbound response as REJECT. What is the most likely cause?

Further reading

On this page