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".
Flow Logs versus Traffic Mirroring
| Item | VPC Flow Logs | Traffic Mirroring |
|---|---|---|
| Captures | Metadata. Addresses, ports, protocol, packets, bytes, ACCEPT or REJECT | Full packets, optionally truncated |
| Attach to | VPC, subnet or network interface | Source network interface (type interface) |
| Output | CloudWatch Logs, S3, Data Firehose | Target ENI, Network Load Balancer, or Gateway Load Balancer endpoint |
| Use | Troubleshooting, audit, anomaly detection | Content inspection, threat monitoring, forensics and attack reverse engineering |
| Cost shape | Vended log ingestion and archive charges | Charged 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-srcaddrandpkt-dstaddrfields 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 shows | Meaning |
|---|---|
| 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 REJECT | Denied 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-directionandtraffic-path. - See Security Lake for querying logs at scale.
Scenarios
The request was accepted, so inbound rules are fine. A security group is stateful and would have allowed the reply,
so the reject on the way out comes from the stateless NACL. The local route always connects subnets in a VPC. The
client's security group also tracks the connection and allows the response.
Related
Further reading
Network Access Analyzer and Reachability Analyzer
Two static VPC analysis tools. One finds unintended access, the other explains why a specific path is blocked.
VPN Options for AWS Access
Site-to-Site VPN, Client VPN, VPN CloudHub and self-managed VPN appliances. Which to choose for offices, remote users and multi-site links.