

This is the new *CloudFormation Template Reference Guide*. Please update your bookmarks and links. For help getting started with CloudFormation, see the [AWS CloudFormation User Guide](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/Welcome.html).

# AWS::EC2::TrafficMirrorSession
<a name="aws-resource-ec2-trafficmirrorsession"></a>

Creates a Traffic Mirror session.

A Traffic Mirror session actively copies packets from a Traffic Mirror source to a Traffic Mirror target. Create a filter, and then assign it to the session to define a subset of the traffic to mirror, for example all TCP traffic.

The Traffic Mirror source and the Traffic Mirror target (monitoring appliances) can be in the same VPC, or in a different VPC connected via VPC peering or a transit gateway. 

By default, no traffic is mirrored. Use [AWS::EC2::TrafficMirrorFilterRule](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-ec2-trafficmirrorfilterrule.html) to specify filter rules that specify the traffic to mirror.

## Syntax
<a name="aws-resource-ec2-trafficmirrorsession-syntax"></a>

To declare this entity in your CloudFormation template, use the following syntax:

### JSON
<a name="aws-resource-ec2-trafficmirrorsession-syntax.json"></a>

```
{
  "Type" : "AWS::EC2::TrafficMirrorSession",
  "Properties" : {
      "[Description](#cfn-ec2-trafficmirrorsession-description)" : String,
      "[NetworkInterfaceId](#cfn-ec2-trafficmirrorsession-networkinterfaceid)" : String,
      "[OwnerId](#cfn-ec2-trafficmirrorsession-ownerid)" : String,
      "[PacketLength](#cfn-ec2-trafficmirrorsession-packetlength)" : Integer,
      "[SessionNumber](#cfn-ec2-trafficmirrorsession-sessionnumber)" : Integer,
      "[Tags](#cfn-ec2-trafficmirrorsession-tags)" : [ Tag, ... ],
      "[TrafficMirrorFilterId](#cfn-ec2-trafficmirrorsession-trafficmirrorfilterid)" : String,
      "[TrafficMirrorTargetId](#cfn-ec2-trafficmirrorsession-trafficmirrortargetid)" : String,
      "[VirtualNetworkId](#cfn-ec2-trafficmirrorsession-virtualnetworkid)" : Integer
    }
}
```

### YAML
<a name="aws-resource-ec2-trafficmirrorsession-syntax.yaml"></a>

```
Type: AWS::EC2::TrafficMirrorSession
Properties:
  [Description](#cfn-ec2-trafficmirrorsession-description): String
  [NetworkInterfaceId](#cfn-ec2-trafficmirrorsession-networkinterfaceid): String
  [OwnerId](#cfn-ec2-trafficmirrorsession-ownerid): String
  [PacketLength](#cfn-ec2-trafficmirrorsession-packetlength): Integer
  [SessionNumber](#cfn-ec2-trafficmirrorsession-sessionnumber): Integer
  [Tags](#cfn-ec2-trafficmirrorsession-tags): 
    - Tag
  [TrafficMirrorFilterId](#cfn-ec2-trafficmirrorsession-trafficmirrorfilterid): String
  [TrafficMirrorTargetId](#cfn-ec2-trafficmirrorsession-trafficmirrortargetid): String
  [VirtualNetworkId](#cfn-ec2-trafficmirrorsession-virtualnetworkid): Integer
```

## Properties
<a name="aws-resource-ec2-trafficmirrorsession-properties"></a>

`Description`  <a name="cfn-ec2-trafficmirrorsession-description"></a>
The description of the Traffic Mirror session.  
*Required*: No  
*Type*: String  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

`NetworkInterfaceId`  <a name="cfn-ec2-trafficmirrorsession-networkinterfaceid"></a>
The ID of the source network interface.  
*Required*: Yes  
*Type*: String  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

`OwnerId`  <a name="cfn-ec2-trafficmirrorsession-ownerid"></a>
The ID of the account that owns the Traffic Mirror session.  
*Required*: No  
*Type*: String  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

`PacketLength`  <a name="cfn-ec2-trafficmirrorsession-packetlength"></a>
The number of bytes in each packet to mirror. These are bytes after the VXLAN header. Do not specify this parameter when you want to mirror the entire packet. To mirror a subset of the packet, set this to the length (in bytes) that you want to mirror. For example, if you set this value to 100, then the first 100 bytes that meet the filter criteria are copied to the target.  
If you do not want to mirror the entire packet, use the `PacketLength` parameter to specify the number of bytes in each packet to mirror.  
For sessions with Network Load Balancer (NLB) Traffic Mirror targets the default `PacketLength` will be set to 8500. Valid values are 1-8500. Setting a `PacketLength` greater than 8500 will result in an error response.  
*Required*: No  
*Type*: Integer  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

`SessionNumber`  <a name="cfn-ec2-trafficmirrorsession-sessionnumber"></a>
The session number determines the order in which sessions are evaluated when an interface is used by multiple sessions. The first session with a matching filter is the one that mirrors the packets.  
Valid values are 1-32766.  
*Required*: Yes  
*Type*: Integer  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

`Tags`  <a name="cfn-ec2-trafficmirrorsession-tags"></a>
The tags to assign to a Traffic Mirror session.  
*Required*: No  
*Type*: Array of [Tag](aws-properties-ec2-trafficmirrorsession-tag.md)  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

`TrafficMirrorFilterId`  <a name="cfn-ec2-trafficmirrorsession-trafficmirrorfilterid"></a>
The ID of the Traffic Mirror filter.  
*Required*: Yes  
*Type*: String  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

`TrafficMirrorTargetId`  <a name="cfn-ec2-trafficmirrorsession-trafficmirrortargetid"></a>
The ID of the Traffic Mirror target.  
*Required*: Yes  
*Type*: String  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

`VirtualNetworkId`  <a name="cfn-ec2-trafficmirrorsession-virtualnetworkid"></a>
The VXLAN ID for the Traffic Mirror session. For more information about the VXLAN protocol, see [RFC 7348](https://datatracker.ietf.org/doc/html/rfc7348). If you do not specify a `VirtualNetworkId`, an account-wide unique ID is chosen at random.  
*Required*: No  
*Type*: Integer  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

## Return values
<a name="aws-resource-ec2-trafficmirrorsession-return-values"></a>

### Ref
<a name="aws-resource-ec2-trafficmirrorsession-return-values-ref"></a>

When you pass the logical ID of this resource to the intrinsic `Ref` function, `Ref` returns the ID of the Traffic Mirror Session.

For more information about using the `Ref` function, see [https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/intrinsic-function-reference-ref.html](https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/intrinsic-function-reference-ref.html).

## Examples
<a name="aws-resource-ec2-trafficmirrorsession--examples"></a>

### Create a traffic mirror session
<a name="aws-resource-ec2-trafficmirrorsession--examples--Create_a_traffic_mirror_session"></a>

This is a traffic mirror session that mirrors the first 100 bytes in each packet.

#### JSON
<a name="aws-resource-ec2-trafficmirrorsession--examples--Create_a_traffic_mirror_session--json"></a>

```
{
  "SampleTrafficMirrorSession": {
    "Type": "AWS::EC2::TrafficMirrorSession",
    "Properties": {
      "Description": "Example traffic mirror session",
      "NetworkInterfaceId": "eni-070203a001EXAMPLE",
      "TrafficMirrorTargetId": "tmt-5319fsEXAMPLE",
      "TrafficMirrorFilterId": "tmf-1tdbhqEXAMPLE",
      "SessionNumber": 1,
      "PacketLength": 100,
      "VirtualNetworkId": 1234,
      "Tags": [
        {
          "Key": "Name",
          "Value": "SampleSession"
        }
      ]
    }
  }
}
```

#### YAML
<a name="aws-resource-ec2-trafficmirrorsession--examples--Create_a_traffic_mirror_session--yaml"></a>

```
SampleTrafficMirrorSession:
  Type: "AWS::EC2::TrafficMirrorSession"
  Properties:
    Description: "Example traffic mirror session"
    NetworkInterfaceId: "eni-070203a001EXAMPLE"
    TrafficMirrorTargetId: "tmt-5319fsEXAMPLE"
    TrafficMirrorFilterId: "tmf-1tdbhqEXAMPLE"
    SessionNumber: 1
    PacketLength: 100
    VirtualNetworkId: 1234
    Tags:
    - Key: "Name"
      Value: "SampleSession"
```

## See also
<a name="aws-resource-ec2-trafficmirrorsession--seealso"></a>
+ [Traffic mirror sessions](https://docs.aws.amazon.com/vpc/latest/mirroring/traffic-mirroring-sessions.html) in *Traffic Mirroring*
+ [CreateTrafficMirrorSession](https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateTrafficMirrorSession.html) in the *Amazon EC2 API Reference*



# AWS::EC2::TrafficMirrorSession Tag
<a name="aws-properties-ec2-trafficmirrorsession-tag"></a>

Specifies a tag. For more information, see [Resource tags](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-resource-tags.html).

## Syntax
<a name="aws-properties-ec2-trafficmirrorsession-tag-syntax"></a>

To declare this entity in your CloudFormation template, use the following syntax:

### JSON
<a name="aws-properties-ec2-trafficmirrorsession-tag-syntax.json"></a>

```
{
  "[Key](#cfn-ec2-trafficmirrorsession-tag-key)" : String,
  "[Value](#cfn-ec2-trafficmirrorsession-tag-value)" : String
}
```

### YAML
<a name="aws-properties-ec2-trafficmirrorsession-tag-syntax.yaml"></a>

```
  [Key](#cfn-ec2-trafficmirrorsession-tag-key): String
  [Value](#cfn-ec2-trafficmirrorsession-tag-value): String
```

## Properties
<a name="aws-properties-ec2-trafficmirrorsession-tag-properties"></a>

`Key`  <a name="cfn-ec2-trafficmirrorsession-tag-key"></a>
The tag key.  
*Required*: Yes  
*Type*: String  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

`Value`  <a name="cfn-ec2-trafficmirrorsession-tag-value"></a>
The tag value.  
*Required*: Yes  
*Type*: String  
*Update requires*: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)

## Examples
<a name="aws-properties-ec2-trafficmirrorsession-tag--examples"></a>

### 
<a name="aws-properties-ec2-trafficmirrorsession-tag--examples--"></a>

This example specifies two tags for the Traffic Mirror session.

#### JSON
<a name="aws-properties-ec2-trafficmirrorsession-tag--examples----json"></a>

```
"Tags" : [
   {
      "Key" : "key1",
      "Value" : "value1"
   },
   {
      "Key" : "key2",
      "Value" : "value2"
   }
]
```

#### YAML
<a name="aws-properties-ec2-trafficmirrorsession-tag--examples----yaml"></a>

```
Tags: 
  - Key: "key1"
    Value: "value1"
  - Key: "key2"
    Value: "value2"
```