Skip to content

create_network_interface

create_network_interface(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    ipv4_prefixes: Optional[Ipv4PrefixList] = None,
    ipv4_prefix_count: Optional[Integer] = None,
    ipv6_prefixes: Optional[Ipv6PrefixList] = None,
    ipv6_prefix_count: Optional[Integer] = None,
    interface_type: Optional[NetworkInterfaceCreationType] = None,
    tag_specifications: Optional[TagSpecificationList] = None,
    client_token: Optional[String] = None,
    enable_primary_ipv6: Optional[Boolean] = None,
    connection_tracking_specification: Optional[
        ConnectionTrackingSpecificationRequest
    ] = None,
    operator: Optional[OperatorRequest] = None,
    subnet_id: Optional[SubnetId] = None,
    description: Optional[String] = None,
    private_ip_address: Optional[String] = None,
    groups: Optional[SecurityGroupIdStringList] = None,
    private_ip_addresses: Optional[PrivateIpAddressSpecificationList] = None,
    secondary_private_ip_address_count: Optional[Integer] = None,
    ipv6_addresses: Optional[InstanceIpv6AddressList] = None,
    ipv6_address_count: Optional[Integer] = None,
    dry_run: Optional[Boolean] = None,
) -> CreateNetworkInterfaceResult

Creates a network interface in the specified subnet.

The number of IP addresses you can assign to a network interface varies by instance type.

For more information about network interfaces, see Elastic network interfaces in the Amazon EC2 User Guide.

Parameters:

  • ipv4_prefixes (Optional[Ipv4PrefixList], default: None ) –

    The IPv4 prefixes assigned to the network interface.

    You can't specify IPv4 prefixes if you've specified one of the following: a count of IPv4 prefixes, specific private IPv4 addresses, or a count of private IPv4 addresses.

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

    The number of IPv4 prefixes that Amazon Web Services automatically assigns to the network interface.

    You can't specify a count of IPv4 prefixes if you've specified one of the following: specific IPv4 prefixes, specific private IPv4 addresses, or a count of private IPv4 addresses.

  • ipv6_prefixes (Optional[Ipv6PrefixList], default: None ) –

    The IPv6 prefixes assigned to the network interface.

    You can't specify IPv6 prefixes if you've specified one of the following: a count of IPv6 prefixes, specific IPv6 addresses, or a count of IPv6 addresses.

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

    The number of IPv6 prefixes that Amazon Web Services automatically assigns to the network interface.

    You can't specify a count of IPv6 prefixes if you've specified one of the following: specific IPv6 prefixes, specific IPv6 addresses, or a count of IPv6 addresses.

  • interface_type (Optional[NetworkInterfaceCreationType], default: None ) –

    The type of network interface. The default is interface.

    If you specify efa-only, do not assign any IP addresses to the network interface. EFA-only network interfaces do not support IP addresses.

    The only supported values are interface, efa, efa-only, and trunk.

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

    The tags to apply to the new network interface.

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

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

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

    If you’re creating a network interface in a dual-stack or IPv6-only subnet, you have the option to assign a primary IPv6 IP address. A primary IPv6 address is an IPv6 GUA address associated with an ENI that you have enabled to use a primary IPv6 address. Use this option if the instance that this ENI will be attached to relies on its IPv6 address not changing. Amazon Web Services will automatically assign an IPv6 address associated with the ENI attached to your instance to be the primary IPv6 address. Once you enable an IPv6 GUA address to be a primary IPv6, you cannot disable it. When you enable an IPv6 GUA address to be a primary IPv6, the first IPv6 GUA will be made the primary IPv6 address until the instance is terminated or the network interface is detached. If you have multiple IPv6 addresses associated with an ENI attached to your instance and you enable a primary IPv6 address, the first IPv6 GUA address associated with the ENI becomes the primary IPv6 address.

  • connection_tracking_specification (Optional[ConnectionTrackingSpecificationRequest], default: None ) –

    A connection tracking specification for the network interface.

  • operator (Optional[OperatorRequest], default: None ) –

    Reserved for internal use.

  • subnet_id (Optional[SubnetId], default: None ) –

    The ID of the subnet to associate with the network interface.

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

    A description for the network interface.

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

    The primary private IPv4 address of the network interface. If you don't specify an IPv4 address, Amazon EC2 selects one for you from the subnet's IPv4 CIDR range. If you specify an IP address, you cannot indicate any IP addresses specified in privateIpAddresses as primary (only one IP address can be designated as primary).

  • groups (Optional[SecurityGroupIdStringList], default: None ) –

    The IDs of the security groups.

  • private_ip_addresses (Optional[PrivateIpAddressSpecificationList], default: None ) –

    The private IPv4 addresses.

    You can't specify private IPv4 addresses if you've specified one of the following: a count of private IPv4 addresses, specific IPv4 prefixes, or a count of IPv4 prefixes.

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

    The number of secondary private IPv4 addresses to assign to a network interface. When you specify a number of secondary IPv4 addresses, Amazon EC2 selects these IP addresses within the subnet's IPv4 CIDR range. You can't specify this option and specify more than one private IP address using privateIpAddresses.

    You can't specify a count of private IPv4 addresses if you've specified one of the following: specific private IPv4 addresses, specific IPv4 prefixes, or a count of IPv4 prefixes.

  • ipv6_addresses (Optional[InstanceIpv6AddressList], default: None ) –

    The IPv6 addresses from the IPv6 CIDR block range of your subnet.

    You can't specify IPv6 addresses using this parameter if you've specified one of the following: a count of IPv6 addresses, specific IPv6 prefixes, or a count of IPv6 prefixes.

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

    The number of IPv6 addresses to assign to a network interface. Amazon EC2 automatically selects the IPv6 addresses from the subnet range.

    You can't specify a count of IPv6 addresses using this parameter if you've specified one of the following: specific IPv6 addresses, specific IPv6 prefixes, or a count of IPv6 prefixes.

    If your subnet has the AssignIpv6AddressOnCreation attribute set, you can override that setting by specifying 0 as the IPv6 address count.

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

Raises:

Source code in docs_src/capo_ec2/_services/ec2.py
def create_network_interface(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    ipv4_prefixes: Optional[
        "capo_ec2.types.ipv4_prefix_list.Ipv4PrefixList"
    ] = None,
    ipv4_prefix_count: Optional["capo_ec2.types.integer.Integer"] = None,
    ipv6_prefixes: Optional[
        "capo_ec2.types.ipv6_prefix_list.Ipv6PrefixList"
    ] = None,
    ipv6_prefix_count: Optional["capo_ec2.types.integer.Integer"] = None,
    interface_type: Optional[
        "capo_ec2.types.network_interface_creation_type.NetworkInterfaceCreationType"
    ] = None,
    tag_specifications: Optional[
        "capo_ec2.types.tag_specification_list.TagSpecificationList"
    ] = None,
    client_token: Optional["capo_ec2.types.string.String"] = None,
    enable_primary_ipv6: Optional["capo_ec2.types.boolean.Boolean"] = None,
    connection_tracking_specification: Optional[
        "capo_ec2.types.connection_tracking_specification_request.ConnectionTrackingSpecificationRequest"
    ] = None,
    operator: Optional["capo_ec2.types.operator_request.OperatorRequest"] = None,
    subnet_id: Optional["capo_ec2.types.subnet_id.SubnetId"] = None,
    description: Optional["capo_ec2.types.string.String"] = None,
    private_ip_address: Optional["capo_ec2.types.string.String"] = None,
    groups: Optional[
        "capo_ec2.types.security_group_id_string_list.SecurityGroupIdStringList"
    ] = None,
    private_ip_addresses: Optional[
        "capo_ec2.types.private_ip_address_specification_list.PrivateIpAddressSpecificationList"
    ] = None,
    secondary_private_ip_address_count: Optional[
        "capo_ec2.types.integer.Integer"
    ] = None,
    ipv6_addresses: Optional[
        "capo_ec2.types.instance_ipv6_address_list.InstanceIpv6AddressList"
    ] = None,
    ipv6_address_count: Optional["capo_ec2.types.integer.Integer"] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> "capo_ec2.types.create_network_interface_result.CreateNetworkInterfaceResult":
    """<p>Creates a network interface in the specified subnet.</p> <p>The number of IP addresses you can assign to a network interface varies by instance type.</p> <p>For more information about network interfaces, see <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html">Elastic network interfaces</a> in the <i>Amazon EC2 User Guide</i>.</p>

    Args:
        ipv4_prefixes: <p>The IPv4 prefixes assigned to the network interface.</p> <p>You can't specify IPv4 prefixes if you've specified one of the following: a count of IPv4 prefixes, specific private IPv4 addresses, or a count of private IPv4 addresses.</p>
        ipv4_prefix_count: <p>The number of IPv4 prefixes that Amazon Web Services automatically assigns to the network interface.</p> <p>You can't specify a count of IPv4 prefixes if you've specified one of the following: specific IPv4 prefixes, specific private IPv4 addresses, or a count of private IPv4 addresses.</p>
        ipv6_prefixes: <p>The IPv6 prefixes assigned to the network interface.</p> <p>You can't specify IPv6 prefixes if you've specified one of the following: a count of IPv6 prefixes, specific IPv6 addresses, or a count of IPv6 addresses.</p>
        ipv6_prefix_count: <p>The number of IPv6 prefixes that Amazon Web Services automatically assigns to the network interface.</p> <p>You can't specify a count of IPv6 prefixes if you've specified one of the following: specific IPv6 prefixes, specific IPv6 addresses, or a count of IPv6 addresses.</p>
        interface_type: <p>The type of network interface. The default is <code>interface</code>.</p> <p>If you specify <code>efa-only</code>, do not assign any IP addresses to the network interface. EFA-only network interfaces do not support IP addresses.</p> <p>The only supported values are <code>interface</code>, <code>efa</code>, <code>efa-only</code>, and <code>trunk</code>.</p>
        tag_specifications: <p>The tags to apply to the new network interface.</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">Ensuring idempotency</a>.</p>
        enable_primary_ipv6: <p>If you’re creating a network interface in a dual-stack or IPv6-only subnet, you have the option to assign a primary IPv6 IP address. A primary IPv6 address is an IPv6 GUA address associated with an ENI that you have enabled to use a primary IPv6 address. Use this option if the instance that this ENI will be attached to relies on its IPv6 address not changing. Amazon Web Services will automatically assign an IPv6 address associated with the ENI attached to your instance to be the primary IPv6 address. Once you enable an IPv6 GUA address to be a primary IPv6, you cannot disable it. When you enable an IPv6 GUA address to be a primary IPv6, the first IPv6 GUA will be made the primary IPv6 address until the instance is terminated or the network interface is detached. If you have multiple IPv6 addresses associated with an ENI attached to your instance and you enable a primary IPv6 address, the first IPv6 GUA address associated with the ENI becomes the primary IPv6 address.</p>
        connection_tracking_specification: <p>A connection tracking specification for the network interface.</p>
        operator: <p>Reserved for internal use.</p>
        subnet_id: <p>The ID of the subnet to associate with the network interface.</p>
        description: <p>A description for the network interface.</p>
        private_ip_address: <p>The primary private IPv4 address of the network interface. If you don't specify an IPv4 address, Amazon EC2 selects one for you from the subnet's IPv4 CIDR range. If you specify an IP address, you cannot indicate any IP addresses specified in <code>privateIpAddresses</code> as primary (only one IP address can be designated as primary).</p>
        groups: <p>The IDs of the security groups.</p>
        private_ip_addresses: <p>The private IPv4 addresses.</p> <p>You can't specify private IPv4 addresses if you've specified one of the following: a count of private IPv4 addresses, specific IPv4 prefixes, or a count of IPv4 prefixes.</p>
        secondary_private_ip_address_count: <p>The number of secondary private IPv4 addresses to assign to a network interface. When you specify a number of secondary IPv4 addresses, Amazon EC2 selects these IP addresses within the subnet's IPv4 CIDR range. You can't specify this option and specify more than one private IP address using <code>privateIpAddresses</code>.</p> <p>You can't specify a count of private IPv4 addresses if you've specified one of the following: specific private IPv4 addresses, specific IPv4 prefixes, or a count of IPv4 prefixes.</p>
        ipv6_addresses: <p>The IPv6 addresses from the IPv6 CIDR block range of your subnet.</p> <p>You can't specify IPv6 addresses using this parameter if you've specified one of the following: a count of IPv6 addresses, specific IPv6 prefixes, or a count of IPv6 prefixes.</p>
        ipv6_address_count: <p>The number of IPv6 addresses to assign to a network interface. Amazon EC2 automatically selects the IPv6 addresses from the subnet range.</p> <p>You can't specify a count of IPv6 addresses using this parameter if you've specified one of the following: specific IPv6 addresses, specific IPv6 prefixes, or a count of IPv6 prefixes.</p> <p>If your subnet has the <code>AssignIpv6AddressOnCreation</code> attribute set, you can override that setting by specifying 0 as the IPv6 address count.</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>

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

    def _handler(
        req: "OperationRequest[capo_ec2.types.create_network_interface_request.CreateNetworkInterfaceRequest]",
    ) -> OperationResponse[
        "capo_ec2.types.create_network_interface_result.CreateNetworkInterfaceResult"
    ]:
        import capo_ec2._operations.amazon_ec2.create_network_interface

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("CreateNetworkInterface")
    )
    input_: capo_ec2.types.create_network_interface_request.CreateNetworkInterfaceRequest = {}
    if ipv4_prefixes is not None:
        input_["ipv4_prefixes"] = ipv4_prefixes
    if ipv4_prefix_count is not None:
        input_["ipv4_prefix_count"] = ipv4_prefix_count
    if ipv6_prefixes is not None:
        input_["ipv6_prefixes"] = ipv6_prefixes
    if ipv6_prefix_count is not None:
        input_["ipv6_prefix_count"] = ipv6_prefix_count
    if interface_type is not None:
        input_["interface_type"] = interface_type
    if tag_specifications is not None:
        input_["tag_specifications"] = tag_specifications
    if client_token is None:
        client_token = str(uuid.uuid4())
    input_["client_token"] = client_token
    if enable_primary_ipv6 is not None:
        input_["enable_primary_ipv6"] = enable_primary_ipv6
    if connection_tracking_specification is not None:
        input_["connection_tracking_specification"] = (
            connection_tracking_specification
        )
    if operator is not None:
        input_["operator"] = operator
    if subnet_id is not None:
        input_["subnet_id"] = subnet_id
    if description is not None:
        input_["description"] = description
    if private_ip_address is not None:
        input_["private_ip_address"] = private_ip_address
    if groups is not None:
        input_["groups"] = groups
    if private_ip_addresses is not None:
        input_["private_ip_addresses"] = private_ip_addresses
    if secondary_private_ip_address_count is not None:
        input_["secondary_private_ip_address_count"] = (
            secondary_private_ip_address_count
        )
    if ipv6_addresses is not None:
        input_["ipv6_addresses"] = ipv6_addresses
    if ipv6_address_count is not None:
        input_["ipv6_address_count"] = ipv6_address_count
    if dry_run is not None:
        input_["dry_run"] = dry_run

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