Skip to content

create_traffic_mirror_session

create_traffic_mirror_session(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    network_interface_id: Optional[NetworkInterfaceId] = None,
    traffic_mirror_target_id: Optional[TrafficMirrorTargetId] = None,
    traffic_mirror_filter_id: Optional[TrafficMirrorFilterId] = None,
    packet_length: Optional[Integer] = None,
    session_number: Optional[Integer] = None,
    virtual_network_id: Optional[Integer] = None,
    description: Optional[String] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
    dry_run: Optional[Boolean] = None,
    client_token: Optional[String] = None,
) -> CreateTrafficMirrorSessionResult

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 CreateTrafficMirrorFilter to create filter rules that specify the traffic to mirror.

Parameters:

  • network_interface_id (Optional[NetworkInterfaceId], default: None ) –

    The ID of the source network interface.

  • traffic_mirror_target_id (Optional[TrafficMirrorTargetId], default: None ) –

    The ID of the Traffic Mirror target.

  • traffic_mirror_filter_id (Optional[TrafficMirrorFilterId], default: None ) –

    The ID of the Traffic Mirror filter.

  • packet_length (Optional[Integer], default: None ) –

    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.

  • session_number (Optional[Integer], default: None ) –

    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.

  • virtual_network_id (Optional[Integer], default: None ) –

    The VXLAN ID for the Traffic Mirror session. For more information about the VXLAN protocol, see RFC 7348. If you do not specify a VirtualNetworkId, an account-wide unique ID is chosen at random.

  • description (Optional[String], default: None ) –

    The description of the Traffic Mirror session.

  • tag_specifications (Optional[TagSpecificationList], default: None ) –

    The tags to assign to a Traffic Mirror session.

  • dry_run (Optional[Boolean], default: None ) –

    Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation. Otherwise, it is UnauthorizedOperation.

  • client_token (Optional[String], default: None ) –

    Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see How to ensure idempotency.

Raises:

Source code in docs_src/capo_ec2/_services/ec2.py
def create_traffic_mirror_session(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    network_interface_id: Optional[
        "capo_ec2.types.network_interface_id.NetworkInterfaceId"
    ] = None,
    traffic_mirror_target_id: Optional[
        "capo_ec2.types.traffic_mirror_target_id.TrafficMirrorTargetId"
    ] = None,
    traffic_mirror_filter_id: Optional[
        "capo_ec2.types.traffic_mirror_filter_id.TrafficMirrorFilterId"
    ] = None,
    packet_length: Optional["capo_ec2.types.integer.Integer"] = None,
    session_number: Optional["capo_ec2.types.integer.Integer"] = None,
    virtual_network_id: Optional["capo_ec2.types.integer.Integer"] = None,
    description: Optional["capo_ec2.types.string.String"] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    client_token: Optional["capo_ec2.types.string.String"] = None,
) -> "capo_ec2.types.create_traffic_mirror_session_result.CreateTrafficMirrorSessionResult":
    """<p>Creates a Traffic Mirror session.</p> <p>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.</p> <p>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. </p> <p>By default, no traffic is mirrored. Use <a href="https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateTrafficMirrorFilter.html">CreateTrafficMirrorFilter</a> to create filter rules that specify the traffic to mirror.</p>

    Args:
        network_interface_id: <p>The ID of the source network interface.</p>
        traffic_mirror_target_id: <p>The ID of the Traffic Mirror target.</p>
        traffic_mirror_filter_id: <p>The ID of the Traffic Mirror filter.</p>
        packet_length: <p>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.</p> <p>If you do not want to mirror the entire packet, use the <code>PacketLength</code> parameter to specify the number of bytes in each packet to mirror.</p> <p>For sessions with Network Load Balancer (NLB) Traffic Mirror targets the default <code>PacketLength</code> will be set to 8500. Valid values are 1-8500. Setting a <code>PacketLength</code> greater than 8500 will result in an error response.</p>
        session_number: <p>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.</p> <p>Valid values are 1-32766.</p>
        virtual_network_id: <p>The VXLAN ID for the Traffic Mirror session. For more information about the VXLAN protocol, see <a href="https://datatracker.ietf.org/doc/html/rfc7348">RFC 7348</a>. If you do not specify a <code>VirtualNetworkId</code>, an account-wide unique ID is chosen at random.</p>
        description: <p>The description of the Traffic Mirror session.</p>
        tag_specifications: <p>The tags to assign to a Traffic Mirror session.</p>
        dry_run: <p>Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is <code>DryRunOperation</code>. Otherwise, it is <code>UnauthorizedOperation</code>.</p>
        client_token: <p>Unique, case-sensitive identifier that you provide to ensure the idempotency of the request. For more information, see <a href="https://docs.aws.amazon.com/ec2/latest/devguide/ec2-api-idempotency.html">How to ensure idempotency</a>.</p>

    Raises:
        capo_ec2.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.create_traffic_mirror_session_request.CreateTrafficMirrorSessionRequest]",
    ) -> OperationResponse[
        "capo_ec2.types.create_traffic_mirror_session_result.CreateTrafficMirrorSessionResult"
    ]:
        import capo_ec2._operations.amazon_ec2.create_traffic_mirror_session

        output, http_response = (
            capo_ec2._operations.amazon_ec2.create_traffic_mirror_session.create_traffic_mirror_session(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateTrafficMirrorSession")
    )
    input_: capo_ec2.types.create_traffic_mirror_session_request.CreateTrafficMirrorSessionRequest = {}
    if network_interface_id is not None:
        input_["network_interface_id"] = network_interface_id
    if traffic_mirror_target_id is not None:
        input_["traffic_mirror_target_id"] = traffic_mirror_target_id
    if traffic_mirror_filter_id is not None:
        input_["traffic_mirror_filter_id"] = traffic_mirror_filter_id
    if packet_length is not None:
        input_["packet_length"] = packet_length
    if session_number is not None:
        input_["session_number"] = session_number
    if virtual_network_id is not None:
        input_["virtual_network_id"] = virtual_network_id
    if description is not None:
        input_["description"] = description
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output