AWS VPC Flow Logs answer a question that security groups alone cannot: what network traffic actually reached, or was rejected by, your EC2 instances. A security group rule may look correct, yet an application still fails to connect, or an unexpected host still sends traffic. AWS VPC Flow Logs record the source, destination, port, protocol, packet count, and accept or reject action for traffic in a VPC, subnet, or network interface, giving you evidence instead of guesses.
This guide shows how to enable AWS VPC Flow Logs, send them to CloudWatch Logs or Amazon S3, read a flow log record, and use CloudWatch Logs Insights to find blocked traffic and unexpected connections. The examples use the AWS CLI and assume you have an existing VPC with at least one EC2 instance, plus permissions to create flow logs and IAM roles.
Prerequisites for AWS VPC Flow Logs
You need an AWS account, the AWS CLI configured with credentials that can manage EC2 and IAM, and a VPC ID to monitor. If you are sending logs to CloudWatch Logs, AWS needs an IAM role that allows the flow logs service to publish to CloudWatch; the console can create that role for you, and the CLI example below references a role you create first. If you are sending logs to S3, the bucket must allow the flow logs service to write to it, and you should enable a lifecycle rule if you do not want logs to accumulate forever.
Flow logs do not capture all traffic. They do not log traffic to the Amazon DNS server, traffic to the instance metadata service at 169.254.169.254, DHCP traffic, or traffic between an instance and the VPC router for some reserved addresses. Knowing those exclusions prevents a false conclusion that “no traffic happened” when the traffic was simply in an excluded category.
Step 1: Enable AWS VPC Flow Logs
You can enable flow logs at the VPC, subnet, or elastic network interface level. Enabling at the VPC level is the simplest choice for monitoring a whole environment, while subnet level is useful when only one tier needs detailed logging. The AWS CLI command below creates a flow log for a VPC and sends it to a CloudWatch Logs group. Replace the VPC ID, role ARN, and log group name with your own values.
aws ec2 create-flow-logs --resource-type VPC --resource-ids vpc-0123456789abcdef0 --traffic-type ALL --log-destination-type cloud-watch-logs --log-destination arn:aws:logs:us-east-1:123456789012:log-group:/aws/vpc/flowlogs --deliver-logs-permission-arn arn:aws:iam::123456789012:role/vpc-flow-logs-role
The --traffic-type option accepts ACCEPT, REJECT, or ALL. Start with ALL during troubleshooting so you can see both successful and blocked connections, then consider switching to REJECT only in a very high-traffic VPC where log volume and cost matter. Flow logs appear within a few minutes of enabling, not instantly, so wait before concluding that logging is broken.
If you prefer S3 as the destination, change --log-destination-type to s3 and set --log-destination to the bucket ARN. S3 is cheaper for long-term retention and works well with Athena queries, while CloudWatch Logs is more convenient for quick interactive queries with Logs Insights. Many teams use CloudWatch for the current week and S3 for archival retention.
Step 2: Read an AWS VPC Flow Logs Record
A flow log record is a space-separated line with fields in a fixed order. The default format includes the version, account ID, interface ID, source address, destination address, source port, destination port, protocol number, packets, bytes, start time, end time, action, and log status. Learning to read one record is the fastest way to debug a connection problem.
2 123456789012 eni-0abc123 src 10.0.1.25 10.0.2.40 49152 443 6 10 8400 1728000000 1728000060 ACCEPT OK

In this example, protocol 6 is TCP, the source is a private address in one subnet, the destination port is 443, and the action is ACCEPT, meaning the security group and network ACL allowed the traffic. A REJECT record with the same fields tells you the traffic was blocked, and the next step is to check the security group attached to the destination interface and the network ACL on its subnet. If you see ACCEPT in flow logs but the application still fails, the problem is above the network layer, such as the application not listening or TLS failing.
You can customise the log format to include fields such as the VPC ID, subnet ID, instance ID, TCP flags, and packet source and destination addresses. Custom formats are useful when you need to distinguish traffic that was rewritten by NAT, because the default format shows the addresses after NAT in some cases. Add only the fields you will actually query, because every extra field adds log volume.
Step 3: Query Flow Logs with CloudWatch Logs Insights
CloudWatch Logs Insights turns flow logs into a searchable dataset. The following query finds the most rejected destination ports in a log group, which is a good starting point when you suspect a misconfigured security group or a scanning host.
fields @timestamp, srcAddr, dstAddr, dstPort, action
| filter action = "REJECT"
| stats count(*) as rejected by dstPort, dstAddr
| sort rejected desc
| limit 20
Another useful query groups rejected traffic by source address, which reveals a single host generating most of the blocked traffic. If that host is one of your own instances, you have a configuration bug to fix; if it is an external address, you have evidence for a firewall or AWS WAF discussion. Save useful queries as CloudWatch Logs Insights saved queries so the whole team runs the same investigation steps.
For cost control, set a retention period on the CloudWatch log group, such as 14 or 30 days, and archive older logs to S3 if you need them for compliance. Flow logs in a busy VPC can generate a large volume of data, so monitor the CloudWatch bill after enabling ALL traffic in production, and narrow the scope to specific subnets if the volume is unexpectedly high.
Troubleshooting AWS VPC Flow Logs
If no logs appear, check the IAM role first. The role must trust the vpc-flow-logs.amazonaws.com service and must allow logs:CreateLogStream and logs:PutLogEvents on the destination log group. A missing or mis-scoped permission is the most common cause of an empty log group. Next, confirm the flow log status with aws ec2 describe-flow-logs and check that the resource ID matches the VPC or subnet you expected.
If logs appear but a specific connection is missing, remember the exclusions: DNS, instance metadata, and DHCP traffic are not logged. Also remember that flow logs aggregate traffic over a time window, so a single short connection may be combined with others, and the timestamps show the window, not the exact packet time. For packet-level detail, you need a different tool, such as VPC Traffic Mirroring or host-level packet capture.
For related AWS networking topics, see our guides to VPC endpoints for private S3 access and launching an EC2 instance. The official reference is the AWS VPC Flow Logs documentation.
Conclusion
AWS VPC Flow Logs turn network debugging from guessing into evidence. Enable them at the VPC level, start with ALL traffic, learn to read one record, and use Logs Insights queries for rejected ports and noisy sources. Set a retention policy so cost stays predictable, and keep flow logs enabled permanently in production — the first time you need them, you will be glad they were already running.