- Lab
- A Cloud Guru
Work with AWS VPC Flow Logs for Network Monitoring
Monitoring network traffic is a critical component of security best practices to meet compliance requirements, investigate security incidents, track key metrics, and configure automated notifications. AWS VPC Flow Logs captures information about the IP traffic going to and from network interfaces in your VPC. In this hands-on lab, we will set up and use VPC Flow Logs published to Amazon CloudWatch, create custom metrics and alerts based on the CloudWatch logs to understand trends and receive notifications for potential security issues, and use Amazon Athena to query and analyze VPC flow logs stored in S3.
Path Info
Table of Contents
-
Challenge
Create a CloudWatch Log Group and a VPC Flow Log to CloudWatch
- Create a VPC flow log to S3, setting the Maximum aggregation interval to 1 minute and the S3 bucket ARN to the VPC Flow Logs S3 Bucket ARN found in the lab credentials or obtained via S3.
- Create a CloudWatch log group. Name it VPCFlowLogs.
- Create a VPC flow log to CloudWatch using the IAM role provided for the lab (the one with DeliverVPCFlowLogsRole in the name) and the CloudWatch log group you created.
- Generate some traffic for the flow logs.
-
Challenge
Create CloudWatch Filters and Alerts
-
Create a CloudWatch log metric filter named
dest-port-22-reject
. For the Metric namespace, use VPC Flow Logs; for Metric name, use SSH Rejects; and for Metric value, enter 1.-
Use the below filter pattern:
[version, account, eni, source, destination, srcport, destport="22", protocol="6", packets, bytes, windowstart, windowend, action="REJECT", flowlogstatus]
-
Use the following for the log data:
2 086112738802 eni-0d5d75b41f9befe9e 61.177.172.128 172.31.83.158 39611 22 6 1 40 1563108188 1563108227 REJECT OK 2 086112738802 eni-0d5d75b41f9befe9e 182.68.238.8 172.31.83.158 42227 22 6 1 44 1563109030 1563109067 REJECT OK 2 086112738802 eni-0d5d75b41f9befe9e 42.171.23.181 172.31.83.158 52417 22 6 24 4065 1563191069 1563191121 ACCEPT OK 2 086112738802 eni-0d5d75b41f9befe9e 61.177.172.128 172.31.83.158 39611 80 6 1 40 1563108188 1563108227 REJECT OK
-
-
Create an alarm called SSH-rejects based on the metric filter.
Note: There may be a New Console Experience button in the top left of the CloudWatch console. These instructions are designed for this new layout, so ensure this is toggled on if it is present.
-
-
Challenge
Use CloudWatch Logs Insights
Apply the Top 20 source IP addresses with highest number of rejected requests sample query.
-
Challenge
Analyze VPC Flow Logs Data in Athena
-
Create the Athena table:
CREATE EXTERNAL TABLE IF NOT EXISTS default.vpc_flow_logs ( version int, account string, interfaceid string, sourceaddress string, destinationaddress string, sourceport int, destinationport int, protocol int, numpackets int, numbytes bigint, starttime int, endtime int, action string, logstatus string ) PARTITIONED BY (dt string) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' ' LOCATION 's3://{your_log_bucket}/AWSLogs/{account_id}/vpcflowlogs/us-east-1/' TBLPROPERTIES ("skip.header.line.count"="1");
-
Create partitions to be able to read the data:
ALTER TABLE default.vpc_flow_logs ADD PARTITION (dt='YYYY-MM-DD') location 's3://{your_log_bucket}/AWSLogs/{account_id}/vpcflowlogs/us-east-1/YYYY/MM/DD';
-
Run the following query in a new query window:
SELECT day_of_week(from_iso8601_timestamp(dt)) AS day, dt, interfaceid, sourceaddress, destinationport, action, protocol FROM vpc_flow_logs WHERE action = 'REJECT' AND protocol = 6 order by sourceaddress LIMIT 100;
-
What's a lab?
Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.