

For Filter, specify the type of traffic to log.(Optional) For Name, enter a name or leave it blank.Create a CloudWatch Log GroupĢ- In the navigation pane, choose Log groups and then choose Create log group.ģ- Enter a name for the log group, and then choose Create.ġ- Navigate to the IAM Console and create a role for EC2 ServiceĢ- Enter the Role name and click on create a roleģ- Open the role and attach the below inline policyĤ- Click on Trust Relationship, choose Edit trust relationship and copy the below policy:Ģ- Select your VPC and then choose Create flow log. In this hands-on giude, we will set up and use VPC Flow Logs and publish the data to Amazon CloudWatch. flow log data is published to a log group, and each network interface has a unique log stream in the log group. Can publish the flow log data directly to Amazon CloudWatch. The include_regions keyword is an iterable of region names used to filter the logs.VPC Flow Logs is a feature that enables you to capture information about the IP traffic going to and from network interfaces in your VPC.The include_accounts keyword is an iterable of account identifiers (as strings) used to filter the logs.The filter_pattern keyword is a string like REJECT or 443 used to filter the logs.If not supplied then the EC2 API will be queried to find out the log format. The fields keyword is a tuple like ('version', 'account-id').When using FlowLogsReader with CloudWatch Logs: region_name is a string like 'us-east-1'.start_time and end_time are Python datetime.datetime objects.You can control what's retrieved with these parameters: It takes a bucket name or a bucket/prefix identifier.īy default these classes will yield records from the last hour. flow_log_reader = FlowLogsReader( 'flowlog_group') > from flowlogs_reader import FlowLogsReader It parses the message in the event, which takes a record like this: flowlogs_reader -location-type='s3' -include-regions='us-east-1,us-east-2' bucket-name/optional-prefix - return logs only for the given regionsįlowRecord takes an event dictionary retrieved from a log stream.flowlogs_reader -location-type='s3' -include-accounts='12345678901,12345678902' bucket-name/optional-prefix - return logs only for the given accounts.flowlogs_reader -filter-pattern='REJECT' location - use the given filter pattern to have the server limit the output.flowlogs_reader -fields='$' - use the given fields to prevent the module from querying EC2 for the log line format.flowlogs_reader -role-arn='arn:aws:iam::12345678901:role/myrole' -external-id='0a1b2c3d' location - use the given role and external ID to connect to a 3rd party's account using sts assume-role.flowlogs_reader -profile='dev_profile' location - use the profile from your local AWS configuration file to specify credentials and regions.flowlogs_reader -region='us-west-2' location - connect to the given AWS region.flowlogs_reader -thread_count=4 location.Give -thread-count to read from multiple log groups or S3 keys at once: See the Python documentation for strptime for information on format strings. Use the -time-format switch to control how start and end times are interpreted. flowlogs_reader -end-time=' 00:00:00' location.

flowlogs_reader -start-time=' 00:00:00' location.You may also specify a -start-time and/or an -end-time.

The default time window is the last hour.

You may combine the output of flowlogs_reader with other command line utilities: This requires that each of the fields in the 5-tuple are present in the data format.
