Sitemap
Lumenyx

Lumenyx

VPC Series Part 7: VPC Monitoring with CloudWatch

7 min readSep 14, 2025

--

Today we’ll be setting up network monitoring for our VPCs. We’ll be using VPC Flow Logs and Amazon CloudWatch.

Network monitoring is important because it allows you to proactively identify and fix issues like performance bottlenecks or security threats before they can cause downtime or affect users.

I will be following this guide from NextWork.

This is part 7 of 9 of the AWS VPC series.

Picking off from part 6, this is our current set up:

Press enter or click to view image in full size
Image sourced from https://learn.nextwork.org/projects/aws-networks-monitoring

This is what we want to achieve by the end of today:

Press enter or click to view image in full size
Image sourced from https://learn.nextwork.org/projects/aws-networks-monitoring

What is Amazon CloudWatch?

It’s a monitoring service that watches over your AWS environment in real time.

It visualises these metrics as dashboards and graphs to help you understand your resources’ health and performance.

CloudWatch can also be set to automatically trigger actions based on these metrics, such as shutting down a VPC that is receiving illegitimate traffic

What is a Flow Log?

A flow log is a record of all IP traffic going to and from network interfaces in your VPC. It is used for network monitoring and troubleshooting, capturing details like source and destination IPs, ports, and if the traffic was accepted or rejected.

SET UP A FLOW LOG IAM POLICY AND ROLE

Currently VPC Flow Logs don’t have the permission to write logs and send them to CloudWatch.

In this step we’ll give VPC Flow Logs the authorisation to write logs to CloudWatch by creating an IAM role and policy. This will allow us to finish the flow log setup for the subnet.

  1. Go to the IAM Console and click on Policies.
  2. Create policy.
  3. Choose JSON.
  4. Replace the default JSON text with the text below:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams"
],
"Resource": "*"
}
]
}
Press enter or click to view image in full size
Image sourced from https://learn.nextwork.org/projects/aws-networks-monitoring

5. Click Next.

6. Policy name: MediumVPCFlowLogsPolicy

7. Create policy.

8. We’ve now created the policy, but we need to create the role.
Roles > Create role.

9. Choose Custom trust policy.

A custom trust policy is a document attached to an IAM role that defines which entities (users, services, or accounts) are trusted to assume that role. It dictates who is granted the authorisation to use the role’s permissions.

10. Replace the JSON code with the code below (the only difference is “Principal”).

{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Statement1",
"Effect": "Allow",
"Principal": {
"Service": "vpc-flow-logs.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}

11. Next.

12. Search and select MediumVPCFlowLogsPolicy.

13. Next.

14. Role name: MediumVPCFlowLogsRole

15. Create role.

Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size

SET UP FLOW LOGS

We are going to set up a way to track all inbound and outbound network traffic for our VPCs and a location to store those records.

Press enter or click to view image in full size
Image sourced from https://learn.nextwork.org/projects/aws-networks-monitoring
  1. Go to the Cloudwatch console.
  2. Confirm that the region is the same one that was used to launch your VPCs. This is because CloudWatch is region-specific. The data collected on a VPC in one region is not automatically available in other regions.
  3. Under Log groups click Logs.
  4. Create log group.
  5. Log group name: MediumVPCFlowLogsGroup
  6. Keep the default settings and click Create.
  7. Go back to the VPC console and choose Your VPCs.
  8. Select Medium-1-vpc.
  9. Actions > Create flow log.
  10. Name — optional: MediumVPCFlowLog
  11. Maximum aggregation interval: 1 minute
    ‘Maximum aggregation interval’ refers to how often traffic flow data will be lumped into a single flow log record. It being set to 1 minute means that flow log records are generated every minute.
  12. Destination log group: MediumVPCFlowLogsGroup
  13. Service role: MediumVPCFlowLogsRole
    We set this up earlier in the ‘SET UP A FLOW LOG IAM POLICY AND ROLE’ section.
  14. Create flow log.
Press enter or click to view image in full size
Press enter or click to view image in full size
Press enter or click to view image in full size
‘Retention setting’, ‘log class’ and KMS key ARN’ is explained in the section below.
Press enter or click to view image in full size
Press enter or click to view image in full size

What is a log group?

Imagine a log group as a folder where you keep related logs together.

Usually logs from the same source or application will go into the same log group HOWEVER, as mentioned above, logs are also region-specific. This means that log data gets created and saved in the region it was created. However you can use CloudWatch dashboards to bring together different logs from different regions.

What does the ‘Retention setting’ refer to?

It refers to how long your logs are valid for before they’re deleted.

What does ‘Log class’ mean?

Standard: Means that the logs that get created will get accessed or analysed frequently.

Infrequent Access: Means that your logs are being stored for long-term archiving. You’re charged less for storage, but higher for each time you access the file for analysis.

TESTING CONNECTION BETWEEN VPCS

In this step, we’ll validate if traffic can be sent between these VPCs publicly and privately.

Get Lumenyx’s stories in your inbox

Join Medium for free to get updates from this writer.

We will do this by having Instance 1 send a message to Instance 2, which also confirms that our VPC peering setup is working correctly.

  1. While on the command line of ‘Instance — Medium VPC 1’, and ping the private IP address of ‘Instance — Medium VPC 2’. For me it looks like ping 10.2.0.159.
    If this is successful then it means that the VPC peering connection is successful and traffic can move between these separate VPCs privately.
  2. Now try and ping it using the Instance — Medium VPC 2’s PUBLIC IP address. For me it looks like ping 13.211.211.208.
    Receiving ping replies from the public IPv4 address means Instance 2 is correctly configured to respond and that Instance 1 can communicate with it over the public internet.

ANALYSE FLOW LOGS

In this step we’ll review the flow logs for VPC 1’s public subnet and analyse the data to get insights into our network’s activity. We’ll be analysing the logs using Log Insights.

Log Insights is a query service that lets you analyse your CloudWatch logs. It helps you search and visualise log data using a query language to quickly find specific events and troubleshoot issues.

  1. Go to the CloudWatch Console and select Log groups.
  2. Click on your Log group.
  3. Choose your Log stream. This is where your individual logs are.
  4. Now go to Log insights.
  5. Within Selection criteria choose MediumVPCFlowLogsGroup.
  6. Select the Saved and sample queries folder on the right hand side.
  7. Drop down VPC Flow Logs.
  8. Drop down Return the tip 10 byte transfers by source and destination IP addresses > Apply.
  9. Run query.
  10. Look at the results of the query.
    These results show the ten pairs of IP addresses that transferred the most data in your VPC. This allows you to identify and investigate any heavy traffic flows or unusual data transfers within your network.
Press enter or click to view image in full size
Press enter or click to view image in full size
‘eni’ means Elastic Network Interface, which is a virtual network card that you can attach to an instance in an Amazon VPC to enable it to communicate with other services.
Press enter or click to view image in full size
Press enter or click to view image in full size

An explanation of what the log entries mean:

Press enter or click to view image in full size

You now know how to look at your VPC’s logs and analyse them using Log Insights!

Here’s what our topology looks like now:

Press enter or click to view image in full size
Image sourced from https://learn.nextwork.org/projects/aws-networks-monitoring

DELETE YOUR RESOURCES — SO YOU DON’T GET CHARGED

Delete these resources:

  • CloudWatch Log Group
  • Delete the CloudWatch IAM Policy (IAM > Policies > Search for “FlowLogs” > Select MediumVPCFlowLogsPolicy > Delete)
  • Delete the CloudWatch IAM Role (IAM > Roles > Search for “FlowLogs” > Select MediumVPCFlowLogsRole > Delete)
  • EC2 Instances
  • Delete VPC Peering Connections
  • Delete your VPCs

The resources below should already be deleted but it’s good practice to check them anyway:

  • Subnets
  • Route tables
  • Internet gateways
  • Network ACLs
  • Security groups

See you in the next one.

--

--