Analyze VPC Flow Logs with Log Analytics

1. Overview ▾

  • Custom VPC Flow logs could be enabled on NLB ENI's for more visibility.
    • To identify targets emitted TCP RST's include the tcp-flags field.
    • In situations where the original source and destination IP addresses are obscured or translated, consider including pkt-srcaddr or pkt-dstaddr fields.
    • To allow for easier analysis, VPC Flow Logs should be configured with the same custom VPC Flow Log format across VPCs and accounts.

Custom Log Format:

TEXT
${account-id} ${vpc-id} ${subnet-id} ${interface-id} ${instance-id} ${srcaddr} ${srcport} ${dstaddr} ${dstport} ${protocol} ${packets} ${bytes} ${action} ${log-status} ${start} ${end} ${flow-direction} ${traffic-path} ${tcp-flags} ${pkt-srcaddr} ${pkt-src-aws-service} ${pkt-dstaddr} ${pkt-dst-aws-service} ${region} ${az-id} ${sublocation-type} ${sublocation-id}

2. Querying VPC Flow Logs ▾

Log Analytics offers more flexibility in query structure (e.g. filters, aggregations and visualizations) and can produce more granular results.

Here is a re:Post article and video that provides four (4) CloudWatch Logs Insights queries to analyze VPC Flow Logs:

  • Aggregating REJECT flows for specific subnets and host IP addresses
  • Filtering on REJECT flows for a specific ENI
  • Aggregating HTTP/HTTPS or SMTP traffic on a given ENI by source IP address, destination IP and destination port
  • Filtering traffic on a given source IP address or subnet

The article provides queries based on the default VPC Flow Log format. When using custom VPC Flow Logs format, the user can arbitrary order the sequence of fields. parse allows CloudWatch Logs Insights to correctly analyze all custom fields.

3. Sample Queries ▾

Here are additional queries you can extend and customize to your use cases.

3.1 Filter Inbound Traffic with RST flags on NLB ENI's

SQL
parse @message "* * * * * * * * * * * * * * * * * * * * * * * * * * *" as account_id, vpc_id, subnet_id, interface_id,instance_id, srcaddr, srcport, dstaddr, dstport, protocol, packets, bytes, action, log_status, start, end, flow_direction, traffic_path, tcp_flags, pkt_srcaddr, pkt_src_aws_service, pkt_dstaddr, pkt_dst_aws_service, region, az_id, sublocation_type, sublocation_id
| filter interface_id in ["eni-0cadc266d476ae847","eni-05c54c575a830536c"] and tcp_flags = 4 and flowDirection = "ingress"
| display @timestamp, interface_id, srcaddr, srcport,dstaddr, dstport, action, tcp_flags, flow_direction
| sort @timestamp desc
| limit 4
@timestampinterface_idsrcaddrsrcportdstaddrdstportactiontcp_flagsflow_direction
2026-07-19 23:59:43.000eni-0cadc266d476ae84710.0.4.988010.0.1.21719358ACCEPT4ingress
2026-07-19 23:59:43.000eni-0cadc266d476ae84710.0.4.988010.0.1.21756381ACCEPT4ingress
2026-07-19 23:59:39.000eni-0cadc266d476ae84710.0.4.1928010.0.1.21763312ACCEPT4ingress
2026-07-19 23:59:33.000eni-0cadc266d476ae84710.0.3.968010.0.1.21722824ACCEPT4ingress

3.2 Top Source IP's attempting SSH (REJECT Traffic)

SQL
parse @message "* * * * * * * * * * * * * * * * * * * * * * * * * * *" as account_id, vpc_id, subnet_id, interface_id,instance_id, srcaddr, srcport, dstaddr, dstport, protocol, packets, bytes, action, log_status, start, end, flow_direction, traffic_path, tcp_flags, pkt_srcaddr, pkt_src_aws_service, pkt_dstaddr, pkt_dst_aws_service, region, az_id, sublocation_type, sublocation_id
| filter action = "REJECT" and protocol = 6 and dstport = 22
| stats sum(bytes) as SSH_Traffic_Volume by srcaddr
| sort by SSH_Traffic_Volume desc
| limit 5
srcaddrSSH_Traffic_Volume
45.148.10.230560
18.118.100.31420
180.167.128.203352
195.178.110.137312
103.217.186.62240

3.3 Top EC2 Instance ID's by Data Transfers

SQL
parse @message "* * * * * * * * * * * * * * * * * * * * * * * * * * *" as account_id, vpc_id, subnet_id, interface_id,instance_id, srcaddr, srcport, dstaddr, dstport, protocol, packets, bytes, action, log_status, start, end, flow_direction, traffic_path, tcp_flags, pkt_srcaddr, pkt_src_aws_service, pkt_dstaddr, pkt_dst_aws_service, region, az_id, sublocation_type, sublocation_id
| stats sum(bytes) as Data_Transferred by instance_id
| sort by Data_Transferred desc
| limit 5
instance_idData_Transferred
-18230378688450
i-0075e2fb3e534ba672579356769762
i-0822bd396bfcc697c2572381315537
i-0fbcb2b36e9b603972518258902455
i-0528f2fbfb68005cd2475195967477

3.4 Timeseries: HTTP Data Stream for Cluster hosted in 2 subnets

SQL
filter dstPort = 80 and (isIpInSubnet(dstAddr, "10.0.4.0/24") or isIpInSubnet(dstAddr, "10.0.3.0/24")) 
| stats sum(bytes) as Data_Transferred by bin(1m)
bin(1m)Data_Transferred
2026-07-20 01:54:00.000887
2026-07-20 01:53:00.00048783
2026-07-20 01:52:00.00096886
2026-07-20 01:51:00.00093636
Log Analytics Timeseries
Fig 2: Isolating a HTTP Data Stream