Skip to content

detach_network_interface

detach_network_interface(
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional[Boolean] = None,
    attachment_id: Optional[NetworkInterfaceAttachmentId] = None,
    force: Optional[Boolean] = None,
) -> None

Detaches a network interface from an instance.

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.

  • attachment_id (Optional[NetworkInterfaceAttachmentId], default: None ) –

    The ID of the attachment.

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

    Specifies whether to force a detachment.

    • Use the Force parameter only as a last resort to detach a network interface from a failed instance.

    • If you use the Force parameter to detach a network interface, you might not be able to attach a different network interface to the same index on the instance without first stopping and starting the instance.

    • If you force the detachment of a network interface, the instance metadata might not get updated. This means that the attributes associated with the detached network interface might still be visible. The instance metadata will get updated when you stop and start the instance.

Raises:

Examples:

To detach a network interface from an instance This example detaches the specified network interface from its attached instance.

>>> client.detach_network_interface(attachment_id='eni-attach-66c4350a')
Source code in docs_src/capo_ec2/_services/ec2.py
def detach_network_interface(
    self,
    *,
    config_overrides: Optional[EC2ClientConfig] = None,
    dry_run: Optional["capo_ec2.types.boolean.Boolean"] = None,
    attachment_id: Optional[
        "capo_ec2.types.network_interface_attachment_id.NetworkInterfaceAttachmentId"
    ] = None,
    force: Optional["capo_ec2.types.boolean.Boolean"] = None,
) -> None:
    """<p>Detaches a network interface from an instance.</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>
        attachment_id: <p>The ID of the attachment.</p>
        force: <p>Specifies whether to force a detachment.</p> <note> <ul> <li> <p>Use the <code>Force</code> parameter only as a last resort to detach a network interface from a failed instance. </p> </li> <li> <p>If you use the <code>Force</code> parameter to detach a network interface, you might not be able to attach a different network interface to the same index on the instance without first stopping and starting the instance.</p> </li> <li> <p>If you force the detachment of a network interface, the <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html">instance metadata</a> might not get updated. This means that the attributes associated with the detached network interface might still be visible. The instance metadata will get updated when you stop and start the instance.</p> </li> </ul> </note>

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

    Examples:
        To detach a network interface from an instance
        This example detaches the specified network interface from its attached instance.

        >>> client.detach_network_interface(attachment_id='eni-attach-66c4350a')
    """

    def _handler(
        req: "OperationRequest[capo_ec2.types.detach_network_interface_request.DetachNetworkInterfaceRequest]",
    ) -> OperationResponse[None]:
        import capo_ec2._operations.amazon_ec2.detach_network_interface

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

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("DetachNetworkInterface")
    )
    input_: capo_ec2.types.detach_network_interface_request.DetachNetworkInterfaceRequest = {}
    if dry_run is not None:
        input_["dry_run"] = dry_run
    if attachment_id is not None:
        input_["attachment_id"] = attachment_id
    if force is not None:
        input_["force"] = force

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