"I tried to delete my Amazon VPC, but I received a dependency error. How can I delete my Amazon VPC?"
I receive a dependency error when I try to delete my Amazon Virtual Private Cloud (Amazon VPC).
"I receive a dependency error when I try to delete my Amazon Virtual Private Cloud (Amazon VPC).Short descriptionWhen you delete an Amazon VPC, all its components are also deleted. These components include subnets, security groups, network access control lists (network ACLs), route tables, internet gateways, and DHCP options. However, before you attempt to delete your Amazon VPC, you must first delete or disassociate all dependent resources. Follow these steps in the order listed here to avoid dependency errors.ResolutionBefore you delete your Amazon VPC, you must delete the dependent resources.You can use the AWS Command Line Interface (AWS CLI) delete-vpc command or the Amazon VPC console to delete your Amazon VPC.Note: If you receive errors when running AWS CLI commands, make sure that you’re using the most recent AWS CLI version.Resolve errors received when trying to delete an Amazon VPC through the AWS CLIThe following error indicates that there are dependencies that you must remove before you can delete the Amazon VPC:"An error occurred (DependencyViolation) when calling the DeleteVpc operation: The vpc 'vpc-id' has dependencies and cannot be deleted."To resolve this error, complete the following steps:1.    Run the following script to find the remaining dependencies:#!/bin/bashvpc="vpc-xxxxxxxxxxxxx"region="yy-yyyy-y"aws ec2 describe-internet-gateways --region $region --filters 'Name=attachment.vpc-id,Values='$vpc | grep InternetGatewayIdaws ec2 describe-subnets --region $region --filters 'Name=vpc-id,Values='$vpc | grep SubnetIdaws ec2 describe-route-tables --region $region --filters 'Name=vpc-id,Values='$vpc | grep RouteTableIdaws ec2 describe-network-acls --region $region --filters 'Name=vpc-id,Values='$vpc | grep NetworkAclIdaws ec2 describe-vpc-peering-connections --region $region --filters 'Name=requester-vpc-info.vpc-id,Values='$vpc | grep VpcPeeringConnectionIdaws ec2 describe-vpc-endpoints --region $region --filters 'Name=vpc-id,Values='$vpc | grep VpcEndpointIdaws ec2 describe-nat-gateways --region $region --filter 'Name=vpc-id,Values='$vpc | grep NatGatewayIdaws ec2 describe-security-groups --region $region --filters 'Name=vpc-id,Values='$vpc | grep GroupIdaws ec2 describe-instances --region $region --filters 'Name=vpc-id,Values='$vpc | grep InstanceIdaws ec2 describe-vpn-connections --region $region --filters 'Name=vpc-id,Values='$vpc | grep VpnConnectionIdaws ec2 describe-vpn-gateways --region $region --filters 'Name=attachment.vpc-id,Values='$vpc | grep VpnGatewayIdaws ec2 describe-network-interfaces --region $region --filters 'Name=vpc-id,Values='$vpc | grep NetworkInterfaceIdaws ec2 describe-carrier-gateways --region $region --filters Name=vpc-id,Values=$vpc | grep CarrierGatewayIdaws ec2 describe-local-gateway-route-table-vpc-associations --region $region --filters Name=vpc-id,Values=$vpc | grep LocalGatewayRouteTableVpcAssociationIdNote: In the preceding script, enter your VPC ID in the vpc field and AWS Region (for example, us-east-1) in the Region field. Also, make sure that you're using credentials with appropriate permissions to run the Describe API calls.2.    Delete the remaining dependencies that you identified in step 1, and then retry deleting your Amazon VPC.Resolve errors received when trying to delete an Amazon VPC through the Amazon VPC console"VPC contains one or more instances, and cannot be deleted until those instances have been terminated."This error indicates that the Amazon VPC has Amazon Elastic Compute Cloud (Amazon EC2) instances running on it. To resolve this error, terminate your instances."VPC contains one or more in-use network interfaces, and cannot be deleted until those network interfaces have been deleted."This error indicates that the Amazon VPC has network interfaces that are in use or available."An error occurred (InvalidParameterValue) when calling the DeleteNetworkInterface operation: Network interface 'eni-aabbccdd' is currently in use."This error indicates that there are requester-managed network interfaces that you can't delete. To delete requester-managed network interfaces, you must delete the AWS service that created the network interfaces.Follow these steps to remove the dependent services:1.    Open the Amazon EC2 console.2.    Select the AWS 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.    Select the network interface and choose the Details tab.5.    Review the Description to see which resources the network interface is attached to.6.    Delete the associated resources. For example, you're deleting a Network Interface and the Requester ID is amazon-elb. Use the value in the Description field of the Elastic Network Interface to identify the load balancer. Then, navigate to the Load Balancer section of the Amazon EC2 console, locate the load balancer, and delete it. Note: If the network interface is a primary one, then it's deleted when you delete the instance."VPC has one or more attached NAT gateways or virtual private gateways, and cannot be deleted until they are detached or deleted."This error indicates that the Amazon VPC has a dependency. To delete them, follow the steps in Delete a NAT gateway and Detaching and deleting a virtual private gateway."The VPC is peered as a requester with at least one other VPC through peering connections."This error indicates that there are active VPC peering connections in the Amazon VPC. To delete them, follow the steps in Delete a VPC peering connection.If you still have dependencies that are blocking the Amazon VPC from deletion, then use the following procedures.To delete the carrier gateway:1.    Open the Amazon VPC console.2.    In the navigation pane, choose Carrier Gateways.3.    Select the carrier gateway, and then choose Actions. Then, choose Delete carrier gateway.4.    In the Delete carrier gateway dialog box, enter Delete, and then choose Delete.To disassociate the VPC from any local gateway route tables:1.    Open the AWS Outposts console.2.    In the navigation pane, choose Local gateway route tables.3.    Select the route table.4.    Choose Actions, and then choose View details.5.    In VPC associations, select the VPC to disassociate, and then choose Disassociate.6.    Choose Disassociate.Related informationWhy can't I detach or delete an elastic network interface that AWS Lambda created?How can I delete my VPC that is shared with another AWS account?Why can't I delete my requester-managed VPC endpoint?Follow"