EC2 refuses to detach a network interface
Can't detach network interfacesShort answer
Three things stop a detach. The primary interface of an instance can never be detached. A requester-managed interface belongs to an AWS service such as RDS or a NAT gateway and can only go when that service's resource is deleted. And the CLI wants the attachment ID, not the interface ID.
Fix it fast
1Find out which cause you have
Describe the interface. Its attachment, its device index and whether a service manages it tell you which cause applies.
aws ec2 describe-network-interfaces --network-interface-ids <eni-id> \ --query "NetworkInterfaces[0].[Attachment.AttachmentId,Attachment.DeviceIndex,RequesterManaged,Description]"2Match what you see, then jump to its fix
- 1
Device index 0, attached to the instance as its default interfaceIt is the primary network interface of the instanceFix - 2
RequesterManaged is true, and the description names a service, for example a VPC endpoint or a NAT gatewayAn AWS service manages the interface (requester-managed)Fix - 3
The command was run with an eni-... value after --attachment-idThe command got the interface ID instead of the attachment IDFix
- 1
What does the error look like?
Can't detach network interfacesYou can't detach a primary network interface from an instance
Cause 1 of 3
It is the primary network interface of the instance
1Check
Every instance has a default network interface called the primary network interface. AWS does not allow it to be detached.
aws ec2 describe-instances --instance-ids <instance-id> --query "Reservations[0].Instances[0].NetworkInterfaces[*].[NetworkInterfaceId,Attachment.DeviceIndex]"2Fix
Keep the primary interface. Detach a secondary interface instead, or terminate the instance, or launch a replacement instance with the setup you want and move the workload.
# detach a secondary interface (device index 1 or higher)
aws ec2 detach-network-interface --attachment-id <eni-attach-id>3Verify
Describe the interface again and see that it no longer has an attachment.
aws ec2 describe-network-interfaces --network-interface-ids <eni-id> --query "NetworkInterfaces[0].Attachment"Confirmed by docs.aws.amazon.com
Cause 2 of 3
An AWS service manages the interface (requester-managed)
1Check
A requester-managed interface is created by a service in your VPC for its own resource, such as an RDS DB instance, a NAT gateway or an interface VPC endpoint. You can view it and edit its tags, but you cannot attach or detach it.
aws ec2 describe-network-interfaces \
--filters "Name=requester-managed,Values=true" \
--query "NetworkInterfaces[*].[NetworkInterfaceId,Description,InterfaceType]" --output table2Fix
Delete the resource that owns the interface. The service then detaches and deletes the interface itself. If the service detached it but left it behind, you can delete the detached interface.
# after deleting the owning resource, if a detached interface remains
aws ec2 delete-network-interface --network-interface-id <eni-id>3Verify
List requester-managed interfaces again and confirm yours is gone.
aws ec2 describe-network-interfaces --network-interface-ids <eni-id>Confirmed by docs.aws.amazon.com
Cause 3 of 3
The command got the interface ID instead of the attachment ID
1Check
detach-network-interface requires --attachment-id, which looks like eni-attach-..., not the eni-... ID of the interface itself.
aws ec2 describe-network-interfaces --network-interface-ids <eni-id> --query "NetworkInterfaces[0].Attachment.AttachmentId" --output text2Fix
Pass the attachment ID. Use --force only as a last resort for an interface on a failed instance.
aws ec2 detach-network-interface --attachment-id eni-attach-66c4350a3Verify
The command prints no output, and the interface no longer has an attachment.
aws ec2 describe-network-interfaces --network-interface-ids <eni-id> --query "NetworkInterfaces[0].Attachment"Confirmed by docs.aws.amazon.com
How do I stop it coming back?
- Put a clear Name tag on every secondary interface you create, so it is not confused with a service's interface.
- Delete service resources (endpoints, NAT gateways, DB instances) through their own service, never by hunting for their interfaces.
- Keep infrastructure in code, so interfaces are created and removed together with what uses them.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
- Loade DriverThe driver side of a delivery platform: live jobs, routing and earnings, past 5K Google Play downloads.
Related fixes
Servers
AWS will not delete your VPC because a network interface is still there
A network interface owned by an AWS service cannot be detached or modified by you
A VPC cannot be deleted while a requester-managed network interface exists in it.
3 causes, each with a fixServers
Status code 460 on an AWS Application Load Balancer
elb_status_code 460 in ALB access logs
A 460 is generated by the load balancer, not by your app.
3 causes, each with a fixServers
Application Load Balancer returns 504 for requests to EC2 instances
HTTPCode_ELB_504_Count
A 504 from an Application Load Balancer means it could not get an answer from a target in time.
4 causes, each with a fixServers
Apache has a certificate, but https:// does not open
No line with :443 in the output of ss -ltnp
HTTPS needs four things at once: mod_ssl loaded, Apache listening on 443, a virtual host on 443 with SSLEngine on, and a firewall that lets 443 in.
4 causes, each with a fixServers
aws emr --steps fails: Error parsing parameter, Expected '=', received 'EOF'
Error parsing parameter '--steps': Expected: '=', received: 'EOF' for input:
The AWS CLI tried to read your option as shorthand key=value pairs and ran out of text where it expected an equals sign.
3 causes, each with a fixServers
AWS CLI says you must specify a region
You must specify a region. You can also configure your region by running "aws configure".
The AWS CLI sends every request to one region and has none to use.
4 causes, each with a fix