Amazon-web-services – I can’t delete the VPC

amazon-web-servicesvpc

I want to delete one of my VPC but when i was trying to delete, this error appeared.

We could not delete the following VPC (vpc-8737bde2 (10.100.0.0/16) | Khoi-VPC)
The vpc 'vpc-8737bde2' has dependencies and cannot be deleted. (Service: AmazonEC2; Status Code: 400; Error Code: DependencyViolation; Request ID: e115d5ca-dd34-4cbb-a439-541b0dc225da)

OK, i checked the Security group and found one group with the description that has the name of my VPC so i thought that was the problem. But this time the error appears again.

We could not delete the following security group (sg-a43c0dc1)

the specified group: "sg-a43c0dc1" name: "default" cannot be deleted by a user (Service: AmazonEC2; Status Code: 400; Error Code: CannotDelete; Request ID: b21c425c-25c7-46e7-baeb-9610710afeca)

I dont know how to delete my VPC, has anyone have any idea?

Best Answer

Most AWS apps that make use of the VPC, don't show its usage under VPC console. (update) Although AWS console say it will detach the resources, you need to check specific VPC resources used by other AWS services.

Here is some :

  1. EC2 instances: Network interface , Security Groups and subnet for any EC2 instance attach to the VPC-subnets. You may choose to

    • TERMINATE(delete) the EC2 instance, or
    • Launch the instance into a "dummy VPC" or public subnet
  2. RDS: DB Security Groups and subnet When create RDS and attach to VPC, you must create a DB Subnet group attach to that VPC. Even you delete the RDS, the DB subnet group(s) stay. So you need to go to the console and delete the DB subnet group(or use aws cli to remove it)

  3. Any other AWS services that make use of VPC

    • Just back track all the services that make use of VPC-id, VPC-Subnet-ID, Security Groups, etc.

(Updated after tested @TheOne pointed out VPC endpoint )
4. VPC endpoint

Things inside VPC that you don't need to worry about when delete VPC

  • Virtual Private Gateways (the console will detach VPG from VPC )
  • VPN Attachments
  • Internet Gateways
  • Route Tables
Related Topic