In this short tutorial we will be discussing how you can enable VPC flow logs in your AWS Account. VPC Flow Logs is an AWS feature which makes it possible to capture IP traffic information traversing the network interfaces in the VPC. We will configure publishing of the collected data to Amazon CloudWatch Logs group but S3 can also be used as destination. Since flow log data is collected outside of the path of your network traffic, it does not affect network throughput or latency.

With access to VPC flow logs you can:

  • Monitor the traffic that is reaching your instance
  • Determine the direction of the traffic to and from the network interfaces
  • Diagnose overly restrictive security group rules

Flow logs can be created or deleted without any risk of impact to network performance. This can be done on a VPC, a subnet, or a network interface. When enabled at VPC or Subnet level each network interface in that subnet or VPC is monitored.

Before you begin you need an installed and configure AWS CLI. Refer to our article below for complete how to article.

Install and Use AWS CLI on Linux – Ubuntu / Debian / CentOS

Confirm your AWS CLI is working by getting identity.

aws sts get-caller-identity

You also need Administrative privileges in your AWS Account to complete this tutorial. Access to AWS Console is also important for data visualization.

Step 1: Create IAM Policy and Role

The first step is creation of an IAM role that will enable service to act on our behalf for logs forwarding. This action can be done on AWS console or from CLI. This is an IAM role to publish flow logs to the CloudWatch log group.

Before Role creation you need an IAM Policy which can be created on IAM > Policies > Create policy > JSON. Paste below data.

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

Give a policy a name and complete creation.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/aws-create-flow-logs-policy-01-1024×648.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" height="648" loading="lazy" src="data:image/svg xml,” width=”1024″>

To create IAM role go to Identity and Access Management (IAM) > Roles > Create role. For trusted entity type choose “AWS service” and “EC2”

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/aws-create-flow-logs-role-01-1024×329.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" height="329" loading="lazy" src="data:image/svg xml,” width=”1024″>

Click Next to attach Permissions. Under “Attach permissions policies” page, select the policy you created before.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/aws-create-flow-logs-role-02-1024×359.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" height="359" loading="lazy" src="data:image/svg xml,” width=”1024″>

Give a role a name to complete creation. I’ll name mine IAM-PublishFlowLogs, same name as policy.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/aws-create-flow-logs-role-03-1024×511.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" height="511" loading="lazy" src="data:image/svg xml,” width=”1024″>

Copy the Role ARN and save it somewhere.

Step 2: Edit Trust Relationships

You will also need to Enable trust relationship so that the IAM role can access the CloudWatch Log group. Go to AWS Roles and click on the role you created in Step 1.

Click “Edit Trust Policy” to update the policy.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/aws-role-edit-trust-relationships-1024×440.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" height="440" loading="lazy" src="data:image/svg xml,” width=”1024″>

Add below contents:

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

Click “Update Trust Policy” button to update the relationship.

Step 3: Create CloudWatch Log group

The CloudWatch log group defines where the log streams are recorded. It is created on Services > CloudWatch > Logs > Actions> Create log group.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/aws-create-log-group-01-1024×208.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" height="208" loading="lazy" src="data:image/svg xml,” width=”1024″>

Hit the Create button to action.

Step 4: Enable AWS VPC Flow Logs

To enable flow logs select Services > VPC > Your VPCs > YourVPCName > Create flow log

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/aws-enable-vpc-flow-logs-01-1024×244.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" height="244" loading="lazy" src="data:image/svg xml,” width=”1024″>

Fill all required information:

  • Give flow log a name
  • Select traffic filter type
  • Aggregation interval
  • Destination – Can be CloudWatch Logs or Amazon S3 bucket
  • Destination Log group in CloudWatch
  • IAM role with permissions to publish to selected Log group
  • Log Format

My settings are as shown in the screenshot below.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/aws-enable-vpc-flow-logs-02-1024×779.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" height="779" loading="lazy" src="data:image/svg xml,” width=”1024″>

Hit the Create flow log button to complete the setup. You can confirm if creation was successful by listing available Flow Logs.

<img alt="" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/aws-enable-vpc-flow-logs-03-1024×238.png" data-ez ezimgfmt="rs rscb8 src ng ngcb8 srcset" height="238" loading="lazy" src="data:image/svg xml,” width=”1024″>

Clicking on Destination name link should take you to the Log group where you can filter log streams. You can also enable from the CLI:

aws ec2 create-flow-logs --resource-type VPC --resource-ids  --traffic-type ALL --log-group-name  --deliver-logs-permission-arn 

More Articles on AWS:

Easily Setup Kubernetes Cluster on AWS with EKS

Create AWS IAM Users & Groups with AWS CLI

How To Rename IAM User name on AWS

Learning materials:


<img alt="AWS Certified Solutions Architect – Associate 2020" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/362328_91f3_10.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/icon_udemy-com.png5f61fc93b2b8d.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>Udemy.com


<img alt="Ultimate AWS Certified Solutions Architect Associate 2020" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/2196488_8fc7_7.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/icon_udemy-com.png5f61fc93b2b8d.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>Udemy.com


<img alt="AWS Certified Developer – Associate 2020" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/393306_f2a5_6.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/icon_udemy-com.png5f61fc93b2b8d.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>Udemy.com


<img alt="Ultimate AWS Certified Developer Associate 2020 – NEW!" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/1921420_384a_12.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/icon_udemy-com.png5f61fc93b2b8d.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>Udemy.com


<img alt="Amazon Web Services (AWS) Certified – 4 Certifications!" data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/1047846_83ef_28.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>

<img data-ezsrc="https://kirelos.com/wp-content/uploads/2020/09/echo/icon_udemy-com.png5f61fc93b2b8d.jpg" ezimgfmt="rs rscb8 src ng ngcb8" src="data:image/svg xml,”>Udemy.com