AWS Amazon EC2 Traffic Mirror Filter
This page shows how to write Terraform and CloudFormation for Amazon EC2 Traffic Mirror Filter and write them securely.
aws_ec2_traffic_mirror_filter (Terraform)
The Traffic Mirror Filter in Amazon EC2 can be configured in Terraform with the resource name aws_ec2_traffic_mirror_filter
. The following sections describe 5 examples of how to use the resource and its parameters.
Example Usage from GitHub
resource "aws_ec2_traffic_mirror_filter" "this" {
description = var.description
network_services = var.network_services
tags = var.tags
}
resource "aws_ec2_traffic_mirror_filter" "filter" {
description = var.filter_description
network_services = ["amazon-dns"]
tags = var.common_tags
}
resource "aws_ec2_traffic_mirror_filter" "filter" {}
resource "aws_ec2_traffic_mirror_filter_rule" "https" {
traffic_mirror_filter_id = aws_ec2_traffic_mirror_filter.filter.id
destination_cidr_block = "0.0.0.0/0"
source_cidr_block = "10.0.0.0/8"
resource "aws_ec2_traffic_mirror_filter" "module_filter" {
description = var.mirror_filt_desc
}
resource "aws_ec2_traffic_mirror_filter_rule" "module_outbound" {
description = "Capture all outbound"
traffic_mirror_filter_id = aws_ec2_traffic_mirror_filter.module_filter.id
resource "aws_ec2_traffic_mirror_filter" "module_filter" {
description = var.mirror_filt_desc
}
resource "aws_ec2_traffic_mirror_filter_rule" "module_outbound" {
description = "Capture all outbound"
traffic_mirror_filter_id = aws_ec2_traffic_mirror_filter.module_filter.id
Parameters
-
arn
optional computed - string -
description
optional - string -
id
optional computed - string -
network_services
optional - set of string -
tags
optional - map from string to string
Explanation in Terraform Registry
Provides an Traffic mirror filter.
Read limits and considerations for traffic mirroring
Tips: Best Practices for The Other AWS Amazon EC2 Resources
In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.
aws_default_vpc
Ensure to avoid using default VPC
It is better to define the own VPC and use it.
aws_network_acl_rule
Ensure your network ACL rule blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
aws_ebs_volume
Ensure to use a customer-managed key for EBS volume encryption
It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).
aws_instance
Ensure to avoid storing AWS access keys in user data
It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.
aws_security_group
Ensure your security group blocks unwanted inbound traffic
It is better to block unwanted inbound traffic.
AWS::EC2::TrafficMirrorFilter (CloudFormation)
The TrafficMirrorFilter in EC2 can be configured in CloudFormation with the resource name AWS::EC2::TrafficMirrorFilter
. The following sections describe 10 examples of how to use the resource and its parameters.
Example Usage from GitHub
Type: "AWS::EC2::TrafficMirrorFilter"
Properties:
Description: "EC2 traffic mirror filter"
Tags:
- Key: "Name"
Value: "VPCFilter"
Type: AWS::EC2::TrafficMirrorFilter
Properties:
Description: Mirror ALL TCP traffic.
Tags:
- { Key: Name, Value: !Sub '${AWS::StackName}-filter-all-traffic' }
Type: AWS::EC2::TrafficMirrorFilter
Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrorfilter.html
Type: AWS::EC2::TrafficMirrorFilter
Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrorfilter.html
Type: AWS::EC2::TrafficMirrorFilter
Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrorfilter.html
"Type": "AWS::EC2::TrafficMirrorFilter",
"Properties": {
"Tags": [{
"Key": "Name",
"Value": {
"Fn::Sub": [
"Type": "AWS::EC2::TrafficMirrorFilter",
"Properties": {
"Description": "DDI Traffic Mirror Filter",
"Tags": [ { "Key": "Name", "Value": "DDITrafficMirrorFilter" }]
}
},
"AWS::EC2::TrafficMirrorFilter": {
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrorfilter.html",
"Properties": {
"Description": {
"Required": false,
"Documentation": "http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrorfilter.html#cfn-ec2-trafficmirrorfilter-description",
"resourceType": "AWS::EC2::TrafficMirrorFilter",
"filePath": null
},
{
"resourceType": "AWS::EC2::SecurityGroupIngress",
"filePath": null
"AWS::EC2::TrafficMirrorFilter": {
"Type": "AWS::EC2::TrafficMirrorFilter",
"Properties": {}
},
"AWS::GameLift::Build": {
"Type": "AWS::GameLift::Build",
Parameters
-
Description
optional - String -
NetworkServices
optional - List -
Tags
optional - List of Tag
Explanation in CloudFormation Registry
Specifies a Traffic Mirror filter.
A Traffic Mirror filter is a set of rules that defines the traffic to mirror.
By default, no traffic is mirrored. To mirror traffic, use AWS::EC2::TrafficMirrorFilterRule to add Traffic Mirror rules to the filter. The rules you add define what traffic gets mirrored.
Frequently asked questions
What is AWS Amazon EC2 Traffic Mirror Filter?
AWS Amazon EC2 Traffic Mirror Filter is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.
Where can I find the example code for the AWS Amazon EC2 Traffic Mirror Filter?
For Terraform, the niveklabs/aws, JamesWoolfenden/terraform-aws-trafficmirror and hands-on-cloud/amazon-vpc-traffic-inspection-and-monitoring source code examples are useful. See the Terraform Example section for further details.
For CloudFormation, the awsvpc/pycompliance, seek-ret/installation and awslabs/aws-service-catalog-products source code examples are useful. See the CloudFormation Example section for further details.