- Newest
- Most votes
- Most comments
Hi there,
Thank you for posting your question here. I’m really sorry to hear about your issue.
I understand that you’re having trouble deleting some resources (VPCs, Subnets, SGs, and Network Interfaces) because of dependencies.
If you were trying to delete an Amazon VPC through the AWS CLI, please try the following:
- Run the following script to find the remaining dependencies. Be 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
NOTE: You can also use the AWS Management Console for Step 2
- Delete the remaining dependencies you identified in step 1,
Make sure you delete or detach all resources associated with your VPCs:
• De-associating any explicit subnet association in your route tables
• Delete custom route tables
• Delete custom network ACLs
• Detach and delete the internet gateway
• Delete subnets
• Delete custom security groups
• Delete VPC peering connections
• Delete Endpoints
• Delete the NAT gateway
• Delete egress-only internet gateway
And then retry deleting your Amazon VPC, see https://docs.aws.amazon.com/vpc/latest/userguide/working-with-vpcs.html#VPC_Deleting.
More information on resolving the dependency error can be found here: https://aws.amazon.com/premiumsupport/knowledge-center/troubleshoot-dependency-error-delete-vpc/
Hopefully this helps. Should you have any further queries or concern, please feel free to reach out.
Thanks,
Ayabulela
The AWS CLI commands worked!
I was able to delete the interfaces using the aws cli command. Once I deleted the ENIs, I was able to delete everything else. So basically, I couldn't delete from the console, but I could delete it using the aws-cli command. Thanks!
"aws ec2 delete-network-interface --network-interface-id eni-061e8154b1bc16528"
Hi
- If you want to delete VPC then first detach ENI then you can delete vpc from was management console. Or
- When you try to delete, you will get the list of items that are up and running that you have to manually delete or detach first like NAT gateway , ENI etc.
Relevant content
- Accepted Answerasked 2 years ago
- asked 3 days ago
- asked 3 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 9 months ago