Creating and Analyzing Network Flow Logs in AWS

Understanding and monitoring your network traffic is crucial for security and performance optimization in the world of AWS cloud administration. You may record and examine network activity inside your Virtual Private Cloud (VPC) environment using Network Flow Logs, a powerful tool provided by Amazon Web Services (AWS).

In this article, we will walk through the creation and analysis of network traffic logs at the VPC, subnet, and network interface levels.

Diagram of network flow log and CloudWatch architecture topology.

Creating VPC Flow Logs and Analyzing with CloudWatch

Step 1. Creating VPC Flow Logs

VPC flow logs provide an overview of all traffic entering and leaving the entire VPC, giving you insights into the overall network behavior.

Log in to your AWS Management Console.

Go to the VPC Dashboard.

Screenshot showing Accessing the VPC in AWS.

Click on the “VPCs.” There will be a list of VPCs that you have created. If you haven’t created a VPC, see our tutorial on how to create a VPC in AWS.

Screenshot showing List of VPCs in AWS.

Choose the target VPC for which you want to enable Flow Logs.

In the navigation pane, click on “Flow Logs.”

Screenshot showing Selecting VPC and creating flow logs in AWS.

Click the “Create Flow Log” button.

Screenshot showing Creating flow log in AWS.

Give the name for the flow log. 

In the “Filter” section select “All.” (You can select “Accept” or “Reject” if you want to capture only accepted or rejected traffic.)

Choose a maximum aggregation interval of 10 minutes. (If we select the maximum aggregation interval to 1 minute then it will produce a higher number of flow logs.)

Screenshot showing Adding and selecting different values for VPC flow log in AWS.

Choose the destination to “Send to CloudWatch Logs.” (We will be sending our flow logs to Cloudwatch.)  

Screenshot showing Selecting the VPC flow log destination in AWS.

Give the name to the destination log group. (A log group is a collection of log streams that have the same monitoring, access control, and retention settings.)

In the IAM role section. Click on “Set up permission.” It will open the IAM section in the new tab. 

Screenshot showing Creating a new IAM role in AWS.

Click on “Create Role.” 

Screenshot showing Creating a new IAM role in AWS.

Select “Custom trust policy” on the trusted entity type. And paste the custom trust policy that I have given below.

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Principal": {
                "Service": [
                    "vpc-flow-logs.amazonaws.com",
                    "ec2.amazonaws.com"
                ]
            },
            "Action": "sts:AssumeRole"
        }
    ]
}
Screenshot showing Adding a custom trust policy in AWS.

Click on “Next”. 

Then click on “Create Policy” in the Add permission section. It will open the new tab.

Screenshot showing Creating a new policy in AWS.

Select “JSON” and paste the following policy.

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "logs:CreateLogGroup",
        "logs:CreateLogStream",
        "logs:PutLogEvents",
        "logs:DescribeLogGroups",
        "logs:DescribeLogStreams"
      ],
      "Resource": "*"
    }
  ]
}