Automate traffic mirroring with AWS Lambda
You can configure a Lambda function to automatically mirror traffic from EC2 instances to your ExtraHop sensors deployed in AWS. We recommend that you configure some form of automation to ensure that all of your EC2 instances are monitored by the ExtraHop system.
This guide provides instructions for configuring and installing an example Lambda function that is available on the ExtraHop GitHub repository. Here's how the function works:
The following steps outline the individual processes described in the above diagram:
- Every time an EC2 instance starts running, a CloudWatch rule runs the Lambda function.
- The function checks to see if a mirror session exists for the new EC2 instance.
- If there is no mirror session for the instance, the function selects which ExtraHop
sensor it will mirror traffic to.
- First, the function searches for sensors that are in the same Availability
Zone as the traffic mirror.
Note: If the function is unable to find any sensors in the same Availability Zone, the LOCAL_ZONE_ONLY variable determines whether the function will select sensors outside of the Availability Zone. Mirroring traffic across Availability Zones carries an additional charge per GB. See the AWS documentation for more information. - Next, the function filters out sensors with security groups that block traffic from the EC2 instance.
- Then the function filters out sensors that are on VPCs with ACLs that block traffic from the EC2 instance.
- After the function has a list of valid sensors, the function searches for the sensor with the lowest number of mirror sessions to ensure that mirror sessions are evenly distributed.
- First, the function searches for sensors that are in the same Availability
Zone as the traffic mirror.
- Finally, the function creates a mirror session that forwards traffic from the EC2 instance to the selected sensor.
Before you begin
- Create traffic mirror targets for each of your ExtraHop sensors. Note the IDs of the targets; you will need to add the IDs to the script.
- Create a traffic mirror filter that determines what traffic will be mirrored to your sensors. Note the ID of the mirror filter; you will need to add the ID to an environment variable in the Lambda function.
Thank you for your feedback. Can we contact you to ask follow up questions?