AWS will not detach or delete an internet gateway
Detaching an internet gateway fails while the VPC still has public addresses in useShort answer
An internet gateway cannot be deleted while it is attached to a VPC, and it cannot be detached while the VPC still has resources with public IP addresses or Elastic IP addresses. Find those addresses, release or remove them, detach the gateway, then delete it.
Fix it fast
1Find out which cause you have
Check whether the gateway is attached, and to which VPC.
aws ec2 describe-internet-gateways \ --internet-gateway-ids igw-0d0fb496b3EXAMPLE \ --query 'InternetGateways[0].Attachments'2Match what you see, then jump to its fix
What does the error look like?
Detaching an internet gateway fails while the VPC still has public addresses in useDeleting an internet gateway fails while it is attached to a VPC
Cause 1 of 2
The gateway is still attached to the VPC
1Check
Delete only works on a detached gateway. The first-step command lists any attachment.
aws ec2 describe-internet-gateways --query 'InternetGateways[].[InternetGatewayId,Attachments[0].VpcId]' --output table2Fix
Detach it from its VPC first, then delete it.
aws ec2 detach-internet-gateway \
--internet-gateway-id igw-0d0fb496b3EXAMPLE \
--vpc-id vpc-0a60eb65b4EXAMPLE
aws ec2 delete-internet-gateway \
--internet-gateway-id igw-0d0fb496b3EXAMPLE3Verify
The gateway no longer appears in the listing.
aws ec2 describe-internet-gateways --internet-gateway-ids igw-0d0fb496b3EXAMPLEConfirmed by docs.aws.amazon.com
Cause 2 of 2
Resources in the VPC still have public IP or Elastic IP addresses
1Check
AWS refuses to detach while the VPC contains resources with associated public IP or Elastic IP addresses; a running instance with one is enough. In the EC2 console, check Elastic IPs and the instances in that VPC that show a public IPv4 address.
aws ec2 describe-internet-gateways --internet-gateway-ids igw-0d0fb496b3EXAMPLE2Fix
Release the Elastic IPs and stop or terminate the instances that hold public addresses, or the other resources that use them, then detach the gateway.
# EC2 console: release the Elastic IPs, stop or terminate instances that hold
# a public address, then detach the gateway with:
aws ec2 detach-internet-gateway --internet-gateway-id igw-0d0fb496b3EXAMPLE --vpc-id vpc-0a60eb65b4EXAMPLE3Verify
Run the detach command again; it returns no output on success.
aws ec2 detach-internet-gateway \
--internet-gateway-id igw-0d0fb496b3EXAMPLE \
--vpc-id vpc-0a60eb65b4EXAMPLEConfirmed by docs.aws.amazon.com
How do I stop it coming back?
- Delete the VPC's resources (instances, NAT gateways, load balancers) before its internet gateway.
- Tag Elastic IPs with their owner so you can tell which ones are safe to release.
- Use infrastructure as code so teardown follows dependency order.
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
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 fixServers
docker login to Amazon ECR fails with: Cannot perform an interactive login from a non TTY device
Cannot perform an interactive login from a non TTY device
Docker asked for a password because none reached it, and a pipe or script has no keyboard to answer.
3 causes, each with a fix