Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't detach network interfaces

I did the AWS misfits tutorial and I thought the cleanup would be as simple as deleting the Cloud Formation stack. However, items failed to delete so I am trying to clean them up manually to assist the Cloud Formation stack deletion.

I keep getting an error when trying to Detach the network interfaces (I am logged into the root account):

Error detaching network interfaces:

eni-0047gfhfgh8ab0e: You are not allowed to manage 'ela-attach' attachments. eni-0f4a46hgfha757e: You are not allowed to manage 'ela-attach' attachments. 

I am unable to delete my VPC without these being deleted.

The stack as a whole is failing to delete because of the following: The following resource(s) failed to delete: [InternetGateway, PublicSubnetTwo, VPC, GatewayAttachement, PublicSubnetOne].

like image 740
Blake Rivell Avatar asked Jul 05 '19 20:07

Blake Rivell


People also ask

Can I detach the primary network interface?

You cannot detach a primary network interface from an instance. You can create and attach additional network interfaces. The maximum number of network interfaces that you can use varies by instance type. For more information, see IP addresses per network interface per instance type.

How do I force delete AWS network interface?

In the navigation pane, under Network Interfaces, search for the VPC ID of the Amazon VPC that you're deleting. Select the network interface and choose the Details tab. Review the Description to see which resources the network interface is attached to. Delete the associated resources.


2 Answers

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.

like image 187
Nebulastic Avatar answered Oct 02 '22 16:10

Nebulastic


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/

like image 23
metanerd Avatar answered Oct 02 '22 18:10

metanerd