64

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.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Souad
  • 4,856
  • 15
  • 80
  • 140
  • Is the VPC empty or are there instances in the VPC's public subnet? – helloV Jul 11 '17 at 07:37
  • Yes there are instances in the subnets. these subnets are attached to virtual gateway not to internet gateway – Souad Jul 11 '17 at 07:42
  • If you have unassociated elastic IPs, release them and try. – helloV Jul 11 '17 at 07:58
  • The thing is that I have no elastic IPs – Souad Jul 11 '17 at 09:46
  • 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. – Michael - sqlbot Jul 11 '17 at 09:52
  • I found a NAT gateway lingering that caused this, and had to delete it. – garryp Feb 01 '19 at 14:15
  • 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. – Xavi Montero Apr 29 '20 at 21:54
  • 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. – Xavi Montero Apr 29 '20 at 21:58

7 Answers7

54

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.

Mark D
  • 3,317
  • 1
  • 26
  • 27
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
24

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.

Ben A
  • 462
  • 4
  • 13
4

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

simplytunde
  • 197
  • 2
  • 7
3

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

smndiaye
  • 438
  • 7
  • 13
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

karuhanga
  • 3,010
  • 1
  • 27
  • 30
  • 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 first – Christopher Thomas May 29 '20 at 07:05
0

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

arul
  • 1
  • 1
0

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.