Wondering how to resolve the vpc has dependencies and cannot be deleted error? We can help you.
At Bobcares, we offer solutions for every query, big and small, as a part of our AWS Support Services.
Let’s take a look at how our Support Team help a customer deal with this AWS error.
How to resolve the vpc has dependencies and cannot be deleted error?
If you use the AWS Command Line Interface (AWS CLI) to delete the Amazon VPC, you must do the following:
- Terminate all instances
- Delete all subnets
- Delete custom security groups and custom route tables
- Detach any internet gateways or virtual private gateways
When you delete your Amazon VPC using the Amazon VPC console, all its components are also deleted.
These components can include subnets, security groups, network access control lists (ACLs), route tables, internet gateways, virtual private gateways, VPC peering connections, or DHCP options.
However, if you don’t delete dependent resources before attempting to delete the Amazon VPC, you’ll receive one of the following dependency errors.
Today, let us see the steps followed by our Support Techs to resolve following errors.
An error occurred (DependencyViolation) when calling the DeleteVpc operation: The vpc <vpc-id> has dependencies and cannot be deleted.
To resolve this error:
1. Firstly, run the following script to find the remaining dependencies. Make sure to replace vpc-id with your VPC ID.
#!/bin/bash
vpc="vpc-xxxxxxxxxxxxx"
aws ec2 describe-internet-gateways --filters 'Name=attachment.vpc-id,Values='$vpc | grep InternetGatewayId
aws ec2 describe-subnets --filters 'Name=vpc-id,Values='$vpc | grep SubnetId
aws ec2 describe-route-tables --filters 'Name=vpc-id,Values='$vpc | grep RouteTableId
aws ec2 describe-network-acls --filters 'Name=vpc-id,Values='$vpc | grep NetworkAclId
aws ec2 describe-vpc-peering-connections --filters 'Name=requester-vpc-info.vpc-id,Values='$vpc | grep VpcPeeringConnectionId
aws ec2 describe-vpc-endpoints --filters 'Name=vpc-id,Values='$vpc | grep VpcEndpointId
aws ec2 describe-nat-gateways --filter 'Name=vpc-id,Values='$vpc | grep NatGatewayId
aws ec2 describe-security-groups --filters 'Name=vpc-id,Values='$vpc | grep GroupId
aws ec2 describe-instances --filters 'Name=vpc-id,Values='$vpc | grep InstanceId
aws ec2 describe-vpn-connections --filters 'Name=vpc-id,Values='$vpc | grep VpnConnectionId
aws ec2 describe-vpn-gateways --filters 'Name=attachment.vpc-id,Values='$vpc | grep VpnGatewayId
aws ec2 describe-network-interfaces --filters 'Name=vpc-id,Values='$vpc | grep NetworkInterfaceId
2. Then, delete the remaining dependencies you identify in step 1, and then retry deleting your Amazon VPC.
VPC contains one or more instances, and cannot be deleted until those instances have been terminated.
Follow these steps to remove the dependent services, and then retry deleting the Amazon VPC
1. Firstly, open the Amazon EC2 console.
2. Then, select the Region that the Amazon VPC is in.
3. In the navigation pane, under Network Interfaces, search for the VPC ID of the Amazon VPC that you’re deleting.
4. Next, select the elastic network interface and choose the Details tab.
5. Review the Description to see which resources the interface is attach to.
6. Finally, delete the associated resources.
Note: If the network interface is a primary network interface, then it’s deleted when you delete the instance.
The following errors indicate that the Amazon VPC has a dependency:
- “Network has some mapped public address(es). Please unmap those public address(es) before detaching the gateway.”
- “VPC has one or more attached internet gateways or virtual private gateways, and cannot delete until they are detached or deleted.”
Follow these steps to remove the dependencies, and then retry deleting the Amazon VPC:
1. Firstly, open the Amazon VPC console.
2. Then, select the Region that the Amazon VPC is in.
3. In the navigation pane, choose NAT Gateways or Virtual Private Gateways.
4. Next, select the NAT gateway or virtual private gateway.
5. Then, review the Description to see which resources the interface is attached to.
6. For Actions, choose Delete NAT Gateway (for internet gateways) or Detach from VPC (for virtual private gateways).
[Need a solution to another query? We are just a click away.]
Conclusion
Today, we saw steps followed by our Support Engineers to resolve the vpc has dependencies error.
PREVENT YOUR SERVER FROM CRASHING!
Never again lose customers to poor server speed! Let us help you.
Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.
0 Comments