Skip to content

VPC Monitoring with Flow Logs

Category Cloud & AWS Networking
Status โœ… Completed
Repo nextwork-vpc-monitoring-with-flow-logs
Original NextWork guide nextwork.ai

Learning project

Practice work following a NextWork guide, separate from my production projects.

๐Ÿ“š NextWork learning project. This is a practice project I built while working through NextWork's VPC Monitoring with Flow Logs guide. It is part of my Learning portfolio and is fully separate from my production projects.

Category: Learning โ€บ Cloud & AWS Networking
Status: โœ… Completed

Overview

This turns on VPC Flow Logs, the VPC's 'diary' of accepted and rejected connections, and analyzes them. The guide creates a CloudWatch log group, an IAM role the flow-logs service can assume, and a flow log on VPC 1. Then it generates traffic over the peering link and queries the logs with Logs Insights.

Summary

Deployed peered VPCs plus a VPC flow log to CloudWatch Logs on real AWS, generated peer pings, and ran my analyzer on real flow records. 12/12 checks passed, and over 349 records it found 3 accepted ICMP flows from the peer VPC and 217 rejected internet probes. Everything was torn down afterwards.

The checks behind this are in docs/verification.txt.

Skills & tools

Amazon VPC, Subnets, CIDR, Terraform, Infrastructure as Code, boto3, moto (AWS mock), VPC Flow Logs, CloudWatch Logs, IAM roles & policies, Log analysis, Python

What I built

  • main.tf: the peering setup, plus a CloudWatch log group, an IAM role with a trust policy for vpc-flow-logs.amazonaws.com, an inline policy scoped to that one log group, and aws_flow_log (ALL traffic).
  • analyze_flow_logs.py: parses v2 flow-log records and reports top talkers, rejected traffic by port, and accepted ICMP from the peer VPC (the Logs Insights questions from the guide).
  • sample-flow-logs.txt: realistic sample records (documentation IP ranges) for testing the analyzer.

How to run

pip install -r requirements-dev.txt   # moto (local AWS mock) + boto3
./local-test.sh                       # terraform apply against the mock, run checks.py, then destroy

# Real AWS (costs money; use your own IAM user/profile):
terraform init && terraform apply      # mock_endpoint defaults to "" = real AWS
terraform destroy                      # clean up when done

Verification

I ran the verification command on 2026-12-02. The full output is in docs/verification.txt.

PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache ./local-test.sh

Real AWS deployment (2026-12-02)

I deployed this project to a real, dedicated AWS learning account (us-east-1, kept separate from everything else I run), checked it, captured the output, and tore it all down right after. Every resource carried the tag Project=nextwork-vpc-monitoring-with-flow-logs so I could prove nothing was left behind.

How I ran it: ./real-aws-run.sh (in this repo) does terraform init/apply with my AWS profile, runs checks.py against the real account, runs real-extra.sh for the live tests, and then always runs terraform destroy, even if a step fails. To get onto the instances I used EC2 Instance Connect with a throwaway SSH key that is only valid for 60 seconds. No key pairs were created in AWS and no keys were saved. My first run was interrupted while it waited for records. I pulled them by hand, let the teardown finish, then re-ran the whole thing for a clean transcript. The re-run's analyzer ran after only about a minute of records, so the earlier run's peer-ICMP findings are appended to the transcript.

Evidence (excerpt; the full, sanitized transcript is in docs/aws-real-run.txt, with the account ID redacted):

$ python3 checks.py   (against the real account)
ALL 12 CHECKS PASSED
$ ./real-extra.sh
--- peering connection status
active  10.1.0.0/16 10.2.0.0/16
--- from VPC 1 instance: ping VPC 2 instance private IP 10.2.0.133
ip-10-1-0-253.ec2.internal
4 packets transmitted, 4 received, 0% packet loss, time 3067ms
rtt min/avg/max/mdev = 0.368/0.963/2.706/1.006 ms
--- generate some extra traffic (a few more pings + a rejected probe on port 3389 from the internet side)
done
--- waiting for flow-log records in CloudWatch log group NextWorkVPCFlowLogsGroup (aggregation interval 60s)
records fetched: 32
--- sample of real records
--- analyze_flow_logs.py on the REAL records
records              32
top_talkers          [('10.1.0.253', 4765), ('100.63.197.102', 3977), ('44.216.198.102', 284), ('13.217.79.129', 232), ('3.87.127.143', 76)]
rejected             18
rejected_by_port     [(('TCP', '9554'), 1), (('TCP', '48810'), 1), (('TCP', '17000'), 1), (('TCP', '10086'), 1), (('TCP', '63107'), 1)]
from_peer_vpc        0
peer_icmp_accepted   0

Teardown

Resources were up from 20:59 to 21:04 CST on 2026-12-02, then destroyed and verified gone:

=== TEARDOWN 2026-12-02 21:03 CST ===
$ terraform destroy -auto-approve -input=false -no-color -var ami_id=ami-000d209a4fc9822c4 -var project_tag=nextwork-vpc-monitoring-with-flow-logs
Destroy complete! Resources: 19 destroyed.
$ terraform state list   (should be empty)
$ aws resourcegroupstaggingapi get-resources --tag-filters Key=Project,Values=nextwork-vpc-monitoring-with-flow-logs
$ live EC2 instances / volumes / VPCs tagged Project=nextwork-vpc-monitoring-with-flow-logs (should be empty)
=== teardown verified 21:04 CST ===
=== APPENDIX: earlier run of the same stack, 2026-12-02 19:32-19:47 CST (interrupted while waiting, then torn down) ===

Cost

Estimated cost of the real run: about $0.03 in total across two runs (two t2.micro instances for about 15 and 5 minutes, plus a few KB of CloudWatch Logs). The account has a $50/month budget with email alerts at $5, $20 and $40, and the whole AWS series is logged in a private spend ledger.


Original project: https://nextwork.ai/projects/6954a600-a89e-56b0-886b-7054da118a3b ยท Part of my NextWork Learning portfolio (hub).

Verification output

From docs/verification.txt:

$ PATH=/workspace/nextwork-portfolio/.venv/bin:$PATH TF_PLUGIN_CACHE_DIR=/workspace/nextwork-portfolio/tf-plugin-cache ./local-test.sh

Success! The configuration is valid.

Apply complete! Resources: 19 added, 0 changed, 0 destroyed.
flow_log_id = "fl-90c76c86528c0876c"
instance_private_ips = {
  "1" = "10.1.0.4"
  "2" = "10.2.0.4"
}
log_group = "NextWorkVPCFlowLogsGroup"
peering_id = "pcx-a340e5719b75c9141"
subnet_ids = {
  "1" = "subnet-f58f1a8f7b4a1b3a2"
  "2" = "subnet-68c1e01346e68f41b"
}
vpc_ids = {
  "1" = "vpc-d3ea597fccff7e2d8"
  "2" = "vpc-85ac96c94915dbc49"
}
PASS: peering connection is active (active)
PASS: peering links VPC 1 and VPC 2
PASS: VPC 1 routes 10.2.0.0/16 via the peering connection
PASS: VPC 2 routes 10.1.0.0/16 via the peering connection
PASS: instance 1 IP is inside VPC 1
PASS: instance 2 IP is inside VPC 2
PASS: flow log captures ALL traffic for VPC 1
PASS: flow log delivers to the CloudWatch log group (arn:aws:logs:us-east-1:123456789012:log-group:NextWorkVPCFlowLogsGroup)
PASS: IAM policy scoped to the flow-log group only
PASS: analyzer parses sample records (NODATA skipped) (8)
PASS: analyzer finds 3 rejected probes (RDP/telnet) ([(('TCP', '3389'), 2), (('TCP', '23'), 1)])
PASS: analyzer sees accepted ICMP from the peer VPC
ALL 12 CHECKS PASSED

[exit code 0]