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

main.tf#L7
resource "aws_ec2_traffic_mirror_filter" "this" {
  description      = var.description
  network_services = var.network_services
  tags             = var.tags
}

aws_ec2_traffic_mirror_filter.filter.tf#L1
resource "aws_ec2_traffic_mirror_filter" "filter" {
  description      = var.filter_description
  network_services = ["amazon-dns"]
  tags             = var.common_tags
}
main.tf#L37
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"
main.tf#L5
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
main.tf#L5
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

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

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.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

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).

risk-label

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.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

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

VPCMirrorCFT.yml#L20
    Type: "AWS::EC2::TrafficMirrorFilter"
    Properties:
      Description: "EC2 traffic mirror filter"
      Tags:
      - Key: "Name"
        Value: "VPCFilter"
vpc-mirroring.yaml#L56
    Type: AWS::EC2::TrafficMirrorFilter
    Properties:
      Description: Mirror ALL TCP traffic.
      Tags:
        - { Key: Name, Value: !Sub '${AWS::StackName}-filter-all-traffic' }

product.template-us-west-2.yaml#L5
    Type: AWS::EC2::TrafficMirrorFilter
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrorfilter.html
product.template-ap-southeast-1.yaml#L5
    Type: AWS::EC2::TrafficMirrorFilter
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrorfilter.html
product.template-ap-south-1.yaml#L5
    Type: AWS::EC2::TrafficMirrorFilter
    Description: http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrorfilter.html
trafficMirrorMonitor_CFTemplate.json#L416
            "Type": "AWS::EC2::TrafficMirrorFilter",
            "Properties": {
                "Tags": [{
                    "Key": "Name",
                    "Value": {
                        "Fn::Sub": [
DDI.json#L260
            "Type": "AWS::EC2::TrafficMirrorFilter",
            "Properties": {
                "Description": "DDI Traffic Mirror Filter",
                "Tags": [ { "Key": "Name", "Value": "DDITrafficMirrorFilter" }]
               }
            },
EC2TrafficMirrorFilterSpecification.json#L22
    "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",
awsResouceIconMatches.json#L194
        "resourceType": "AWS::EC2::TrafficMirrorFilter",
        "filePath": null
      },
      {
        "resourceType": "AWS::EC2::SecurityGroupIngress",
        "filePath": null
template.json#L1803
    "AWS::EC2::TrafficMirrorFilter": {
      "Type": "AWS::EC2::TrafficMirrorFilter",
      "Properties": {}
    },
    "AWS::GameLift::Build": {
      "Type": "AWS::GameLift::Build",

Parameters

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.