Can't delete AWS internet Gateway
Asked Answered
B

7

71

I created an internet gateway in AWS VPC dashboard, I attached it to a VPC then I want to detach it but I keep getting this error:

Network vpc-xxxx has some mapped public adresses, Please unmap those public addresses before detaching the gateway. ( Service: AmazonEC2; Status Code: 400; Error Code: DependencyViolation; Request ID: qfdqsdf)

What to do to detache this IGW ? Why exactly do I get this error?

I need to get rid of this IGW without deleting extra resources. please any ideas?

For information, the route table of the VPC does contain public addresses but they are routed to other targets. This IGW is not set as target anywhere.

Boyce answered 11/7, 2017 at 7:16 Comment(8)
Is the VPC empty or are there instances in the VPC's public subnet?Irritant
Yes there are instances in the subnets. these subnets are attached to virtual gateway not to internet gatewayBoyce
If you have unassociated elastic IPs, release them and try.Irritant
The thing is that I have no elastic IPsBoyce
Why do you "need" to get rid of an Internet Gateway? This implies you have no instances with public or elastic IP addresses, no NAT Gateways, no external ELBs, and no other resources with an elastic network interface with associated public IP addresses... yet, for some reason you did attach an IGW to your VPC, and it's unclear why that might have been or why you now want to remove it.Flabbergast
I found a NAT gateway lingering that caused this, and had to delete it.Dollhouse
I am in the same situation (although in a VPC I created tfor test). Thing is: If the VPC+subnets+instances+public-IPs could live 'before' the internet gateway was attached, I don't see any reason for it not being able to detach after an attach. I mean... I have a table. I put a glass. I want to remove the glass. It says "there's thirsty people there". Okey... before placing the glass, the table had no glasses and that's all.Benge
Additionally, if I'm not misunderstood, the Internet Gateway allows OUTGOING traffic. I mean: I might want to have a host with a public IP to reach it via ssh, but maybe I don't wont that host to start connections to the outside world. Isn't the Internet Gateway intended only for outgoing traffic? Maybe I'm confused with that.Benge
A
62

You have some resources in the VPC that have been assigned a Public IP address, such as:

  • Amazon EC2 instances
  • Amazon RDS instances
  • Amazon Redshift cluster
  • VPC NAT Gateways
  • etc.

These IP addresses might have been assigned as an Elastic IP address or as an "auto-assign Public IP address" on instance creation.

You will need to delete these Elastic IP addresses before the Internet Gateway can be removed. If they were auto-assigned IP addresses, then Stop the instances to remove the public IP addresses.

You might also need to edit your Route Tables so that they do not refer to the Internet Gateway.

Avaavadavat answered 11/7, 2017 at 9:52 Comment(4)
Thanks for RDS tip, in my case someone did set up a database without cloudformation and caused the vpc stack to not be deletable.Guerra
Also EC2->Network Interfaces-> filter by VPC Id. In our case there were left-over Client VPN IP assignments.Weinhardt
I can't think of anything that fits under the "etc." category, but I guess AWS is releasing new services all the time.Fireweed
Load balancers fit in "etc"Turfman
T
27

had eks in a vpc, deleted the cluster but now there's network interfaces with an EIP and sg attached to them that were loadbalancers that did not get deleted when deleting the cluster because the deployments were not deleted inside the cluster before deleting the cluster itself. Had to find all associated ELB's and delete them, then security groups, then intefaces, EIP, all the way down the line till finally deleting the internet gateway and vpc.

Triaxial answered 17/7, 2019 at 11:21 Comment(3)
Delete the load balancer helps!Isolecithal
Delete NAT gateway alsoSupercharge
I also had to delete the security groupsVaginitis
K
4

I had to delete NAT gateway that was hanging around to resolve mine.

Keratinize answered 18/6, 2018 at 10:46 Comment(1)
Was ELB + sec groups in my caseMannos
S
4

For those facing the same problem check also Route tables having the Internet Gateway as target

Schuman answered 23/9, 2018 at 15:50 Comment(0)
S
2

Personally, I had to manually reject connections from the endpoint services in the VPC.
Endpoint Services > Select Service > Endpoint Connections > Select connection > Actions > Reject endpoint connection request

Shaff answered 23/9, 2019 at 15:11 Comment(1)
Yeah if you have a VPC Private Link in an API Gateway I need to do this in order to delete them. You need to reject the connection like you mentioned firstVirescent
H
1

In my case, I had to delete 5 x Classic Load Balancers that were part of the VPC which I wanted to remove the Internet Gateway from.

Hebdomadal answered 13/6, 2023 at 14:42 Comment(0)
C
0

In my case, I had to remove the dependency of Public IP from the DMS Replication instance.

Cahoot answered 6/9, 2022 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.