Can't detach network interfaces

Solution 1:

I had the same issue, which gave me the following message:

enter image description here

This could be because there is a service in use which still uses the network interface. You could try some of the following things:

  • Remove unused VPC links from API gateway
  • Remove unused VPC Endpoint services
  • Remove unused NAT gateways
  • Remove unused ECS/EKS clusters
  • Remove unused load balancers
  • Remove unused EFS mounts

If that doesn't help, there is something wrong/stuck on the underlying OS, you should wait for it to resolve by itself or report it. I had an ENI deployed by a Lambda function after deleting the lambda function, the ENI got stuck. After some time I was able to detach the ENI.

Solution 2:

AWS offers this bash script as help to find out the dependencies:

#!/bin/bash
vpc="vpc-xxxxxxxxxxxxx" 
aws ec2 describe-internet-gateways --filters 'Name=attachment.vpc-id,Values='$vpc | grep InternetGatewayId
aws ec2 describe-subnets --filters 'Name=vpc-id,Values='$vpc | grep SubnetId
aws ec2 describe-route-tables --filters 'Name=vpc-id,Values='$vpc | grep RouteTableId
aws ec2 describe-network-acls --filters 'Name=vpc-id,Values='$vpc | grep NetworkAclId
aws ec2 describe-vpc-peering-connections --filters 'Name=requester-vpc-info.vpc-id,Values='$vpc | grep VpcPeeringConnectionId
aws ec2 describe-vpc-endpoints --filters 'Name=vpc-id,Values='$vpc | grep VpcEndpointId
aws ec2 describe-nat-gateways --filter 'Name=vpc-id,Values='$vpc | grep NatGatewayId
aws ec2 describe-security-groups --filters 'Name=vpc-id,Values='$vpc | grep GroupId
aws ec2 describe-instances --filters 'Name=vpc-id,Values='$vpc | grep InstanceId
aws ec2 describe-vpn-connections --filters 'Name=vpc-id,Values='$vpc | grep VpnConnectionId
aws ec2 describe-vpn-gateways --filters 'Name=attachment.vpc-id,Values='$vpc | grep VpnGatewayId
aws ec2 describe-network-interfaces --filters 'Name=vpc-id,Values='$vpc | grep NetworkInterfaceId

My issue was a Transit Gateway Attachment and I could figure it out at some point.

Source: https://aws.amazon.com/premiumsupport/knowledge-center/troubleshoot-dependency-error-delete-vpc/

Solution 3:

I had this same issue. For me, I had to delete an Endpoint Service associated with my ELB first, then I could start to get rid of the network interfaces that were set up.

Solution 4:

Try to verify if you have a EFS mount target asociated at the ENI and delete it, after try to delete the network interface that's work for me.