Skip to content

create_flow_logs

create_flow_logs(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional[Boolean] = None,
    client_token: Optional[String] = None,
    deliver_logs_permission_arn: Optional[String] = None,
    deliver_cross_account_role: Optional[String] = None,
    log_group_name: Optional[String] = None,
    resource_ids: Optional[FlowLogResourceIds] = None,
    resource_type: Optional[FlowLogsResourceType] = None,
    traffic_type: Optional[TrafficType] = None,
    log_destination_type: Optional[LogDestinationType] = None,
    log_destination: Optional[String] = None,
    log_format: Optional[String] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
    max_aggregation_interval: Optional[Integer] = None,
    destination_options: Optional[DestinationOptionsRequest] = None,
    tag_field_specifications: Optional[TagFieldSpecificationListRequest] = None,
) -> CreateFlowLogsResult

Creates one or more flow logs to capture information about IP traffic for a specific network interface, subnet, or VPC.

Flow log data for a monitored network interface is recorded as flow log records, which are log events consisting of fields that describe the traffic flow. For more information, see Flow log records in the Amazon VPC User Guide.

When publishing to CloudWatch Logs, flow log records are published to a log group, and each network interface has a unique log stream in the log group. When publishing to Amazon S3, flow log records for all of the monitored network interfaces are published to a single log file object that is stored in the specified bucket.

For more information, see VPC Flow Logs in the Amazon VPC User Guide.

Parameters:

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

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

    The ARN of the IAM role that allows Amazon EC2 to publish flow logs to the log destination.

    This parameter is required if the destination type is cloud-watch-logs, or if the destination type is kinesis-data-firehose and the delivery stream and the resources to monitor are in different accounts.

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

    The ARN of the IAM role that allows Amazon EC2 to publish flow logs across accounts.

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

    The name of a new or existing CloudWatch Logs log group where Amazon EC2 publishes your flow logs.

    This parameter is valid only if the destination type is cloud-watch-logs.

  • resource_ids (Optional[FlowLogResourceIds], default: None ) –

    The IDs of the resources to monitor. For example, if the resource type is VPC, specify the IDs of the VPCs.

    Constraints: Maximum of 25 for transit gateway resource types. Maximum of 300 for the other resource types.

  • resource_type (Optional[FlowLogsResourceType], default: None ) –

    The type of resource to monitor.

  • traffic_type (Optional[TrafficType], default: None ) –

    The type of traffic to monitor (accepted traffic, rejected traffic, or all traffic). This parameter is not supported for transit gateway resource types. It is required for the other resource types.

  • log_destination_type (Optional[LogDestinationType], default: None ) –

    The type of destination for the flow log data.

    Default: cloud-watch-logs

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

    The destination for the flow log data. The meaning of this parameter depends on the destination type.

    • If the destination type is cloud-watch-logs, specify the ARN of a CloudWatch Logs log group. For example:

      arn:aws:logs:region:account_id:log-group:my_group

      Alternatively, use the LogGroupName parameter.

    • If the destination type is s3, specify the ARN of an S3 bucket. For example:

      arn:aws:s3:::my_bucket/my_subfolder/

      The subfolder is optional. Note that you can't use AWSLogs as a subfolder name.

    • If the destination type is kinesis-data-firehose, specify the ARN of a Kinesis Data Firehose delivery stream. For example:

      arn:aws:firehose:region:account_id:deliverystream:my_stream

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

    The fields to include in the flow log record. List the fields in the order in which they should appear. If you omit this parameter, the flow log is created using the default format. If you specify this parameter, you must include at least one field. For more information about the available fields, see Flow log records in the Amazon VPC User Guide or Transit Gateway Flow Log records in the Amazon Web Services Transit Gateway Guide.

    Specify the fields using the ${field-id} format, separated by spaces.

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

    The tags to apply to the flow logs.

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

    The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. The possible values are 60 seconds (1 minute) or 600 seconds (10 minutes). This parameter must be 60 seconds for transit gateway resource types.

    When a network interface is attached to a Nitro-based instance, the aggregation interval is always 60 seconds or less, regardless of the value that you specify.

    Default: 600

  • destination_options (Optional[DestinationOptionsRequest], default: None ) –

    The destination options.

  • tag_field_specifications (Optional[TagFieldSpecificationListRequest], default: None ) –

    The tag configuration associated with the Flow Logs Amazon EC2 Tags feature fields in your custom log format.

Raises:

Source code in docs_src/capo_ec2/_services/ec2.py
def create_flow_logs(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    client_token: Optional["capo_ec2.types.string.String"] = None,
    deliver_logs_permission_arn: Optional["capo_ec2.types.string.String"] = None,
    deliver_cross_account_role: Optional["capo_ec2.types.string.String"] = None,
    log_group_name: Optional["capo_ec2.types.string.String"] = None,
    resource_ids: Optional[
        "capo_ec2.types.flow_log_resource_ids.FlowLogResourceIds"
    ] = None,
    resource_type: Optional[
        "capo_ec2.types.flow_logs_resource_type.FlowLogsResourceType"
    ] = None,
    traffic_type: Optional["capo_ec2.types.traffic_type.TrafficType"] = None,
    log_destination_type: Optional[
        "capo_ec2.types.log_destination_type.LogDestinationType"
    ] = None,
    log_destination: Optional["capo_ec2.types.string.String"] = None,
    log_format: Optional["capo_ec2.types.string.String"] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
    max_aggregation_interval: Optional["capo_ec2.types.integer.Integer"] = None,
    destination_options: Optional[
        "capo_ec2.types.destination_options_request.DestinationOptionsRequest"
    ] = None,
    tag_field_specifications: Optional[
        "capo_ec2.types.tag_field_specification_list_request.TagFieldSpecificationListRequest"
    ] = None,
) -> "capo_ec2.types.create_flow_logs_result.CreateFlowLogsResult":
    """<p>Creates one or more flow logs to capture information about IP traffic for a specific network interface, subnet, or VPC. </p> <p>Flow log data for a monitored network interface is recorded as flow log records, which are log events consisting of fields that describe the traffic flow. For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/flow-log-records.html">Flow log records</a> in the <i>Amazon VPC User Guide</i>.</p> <p>When publishing to CloudWatch Logs, flow log records are published to a log group, and each network interface has a unique log stream in the log group. When publishing to Amazon S3, flow log records for all of the monitored network interfaces are published to a single log file object that is stored in the specified bucket.</p> <p>For more information, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/flow-logs.html">VPC Flow Logs</a> in the <i>Amazon VPC User Guide</i>.</p>

    Args:
        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>
        deliver_logs_permission_arn: <p>The ARN of the IAM role that allows Amazon EC2 to publish flow logs to the log destination.</p> <p>This parameter is required if the destination type is <code>cloud-watch-logs</code>, or if the destination type is <code>kinesis-data-firehose</code> and the delivery stream and the resources to monitor are in different accounts.</p>
        deliver_cross_account_role: <p>The ARN of the IAM role that allows Amazon EC2 to publish flow logs across accounts.</p>
        log_group_name: <p>The name of a new or existing CloudWatch Logs log group where Amazon EC2 publishes your flow logs.</p> <p>This parameter is valid only if the destination type is <code>cloud-watch-logs</code>.</p>
        resource_ids: <p>The IDs of the resources to monitor. For example, if the resource type is <code>VPC</code>, specify the IDs of the VPCs.</p> <p>Constraints: Maximum of 25 for transit gateway resource types. Maximum of 300 for the other resource types.</p>
        resource_type: <p>The type of resource to monitor.</p>
        traffic_type: <p>The type of traffic to monitor (accepted traffic, rejected traffic, or all traffic). This parameter is not supported for transit gateway resource types. It is required for the other resource types.</p>
        log_destination_type: <p>The type of destination for the flow log data.</p> <p>Default: <code>cloud-watch-logs</code> </p>
        log_destination: <p>The destination for the flow log data. The meaning of this parameter depends on the destination type.</p> <ul> <li> <p>If the destination type is <code>cloud-watch-logs</code>, specify the ARN of a CloudWatch Logs log group. For example:</p> <p>arn:aws:logs:<i>region</i>:<i>account_id</i>:log-group:<i>my_group</i> </p> <p>Alternatively, use the <code>LogGroupName</code> parameter.</p> </li> <li> <p>If the destination type is <code>s3</code>, specify the ARN of an S3 bucket. For example:</p> <p>arn:aws:s3:::<i>my_bucket</i>/<i>my_subfolder</i>/</p> <p>The subfolder is optional. Note that you can't use <code>AWSLogs</code> as a subfolder name.</p> </li> <li> <p>If the destination type is <code>kinesis-data-firehose</code>, specify the ARN of a Kinesis Data Firehose delivery stream. For example:</p> <p>arn:aws:firehose:<i>region</i>:<i>account_id</i>:deliverystream:<i>my_stream</i> </p> </li> </ul>
        log_format: <p>The fields to include in the flow log record. List the fields in the order in which they should appear. If you omit this parameter, the flow log is created using the default format. If you specify this parameter, you must include at least one field. For more information about the available fields, see <a href="https://docs.aws.amazon.com/vpc/latest/userguide/flow-log-records.html">Flow log records</a> in the <i>Amazon VPC User Guide</i> or <a href="https://docs.aws.amazon.com/vpc/latest/tgw/tgw-flow-logs.html#flow-log-records">Transit Gateway Flow Log records</a> in the <i>Amazon Web Services Transit Gateway Guide</i>.</p> <p>Specify the fields using the <code>${field-id}</code> format, separated by spaces.</p>
        tag_specifications: <p>The tags to apply to the flow logs.</p>
        max_aggregation_interval: <p>The maximum interval of time during which a flow of packets is captured and aggregated into a flow log record. The possible values are 60 seconds (1 minute) or 600 seconds (10 minutes). This parameter must be 60 seconds for transit gateway resource types.</p> <p>When a network interface is attached to a <a href="https://docs.aws.amazon.com/ec2/latest/instancetypes/ec2-nitro-instances.html">Nitro-based instance</a>, the aggregation interval is always 60 seconds or less, regardless of the value that you specify.</p> <p>Default: 600</p>
        destination_options: <p>The destination options.</p>
        tag_field_specifications: <p>The tag configuration associated with the Flow Logs Amazon EC2 Tags feature fields in your custom log format.</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_flow_logs_request.CreateFlowLogsRequest]",
    ) -> OperationResponse[
        "capo_ec2.types.create_flow_logs_result.CreateFlowLogsResult"
    ]:
        import capo_ec2._operations.amazon_ec2.create_flow_logs

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateFlowLogs")
    )
    input_: capo_ec2.types.create_flow_logs_request.CreateFlowLogsRequest = {}
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if client_token is not None:
        input_["client_token"] = client_token
    if deliver_logs_permission_arn is not None:
        input_["deliver_logs_permission_arn"] = deliver_logs_permission_arn
    if deliver_cross_account_role is not None:
        input_["deliver_cross_account_role"] = deliver_cross_account_role
    if log_group_name is not None:
        input_["log_group_name"] = log_group_name
    if resource_ids is not None:
        input_["resource_ids"] = resource_ids
    if resource_type is not None:
        input_["resource_type"] = resource_type
    if traffic_type is not None:
        input_["traffic_type"] = traffic_type
    if log_destination_type is not None:
        input_["log_destination_type"] = log_destination_type
    if log_destination is not None:
        input_["log_destination"] = log_destination
    if log_format is not None:
        input_["log_format"] = log_format
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications
    if max_aggregation_interval is not None:
        input_["max_aggregation_interval"] = max_aggregation_interval
    if destination_options is not None:
        input_["destination_options"] = destination_options
    if tag_field_specifications is not None:
        input_["tag_field_specifications"] = tag_field_specifications

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