Skip to Content

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 OK

The 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

Three ways to use VPC Flow Logs: send them to CloudWatch Logs and use Contributor Insights to find the top-10 IP addresses; send them to CloudWatch Logs with a metric filter and alarm that alerts SNS, for example on SSH or RDP traffic; or store them in S3, query them with Athena and visualize them in QuickSight Three ways to use VPC Flow Logs: send them to CloudWatch Logs and use Contributor Insights to find the top-10 IP addresses; send them to CloudWatch Logs with a metric filter and alarm that alerts SNS, for example on SSH or RDP traffic; or store them in S3, query them with Athena and visualize them in QuickSight

Find top talkers, alert on bad traffic, or analyse at scale.
  • 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

VPC Traffic Mirroring: inbound and outbound traffic of source ENIs A and B is copied, optionally filtered and truncated, to a target, a Network Load Balancer, a Gateway Load Balancer or a single ENI, in front of a fleet of security appliances that inspect it VPC Traffic Mirroring: inbound and outbound traffic of source ENIs A and B is copied, optionally filtered and truncated, to a target, a Network Load Balancer, a Gateway Load Balancer or a single ENI, in front of a fleet of security appliances that inspect it

A copy of the real packets, for deep inspection.

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:

AWS documentation

On this page

Open notes

Spotted a mistake?

These notes are open source. Suggest a fix, or star the repo if they helped you.

Suggest an edit

For AI agents: llms.txt · llms-full.txt