Not able to delete VPCs, Subnets, SGs, and Network Interfaces

0

Hi,

I attempted to do the ECS Fargate DevOps Workshop to deploy a cluster.

Basically, it uses Cloudformation to create and delete the stack. Cloudformation stack kept failing in deleting some resources.
One example: "DELETE_FAILED" error with status reason as "...Status Code: 400; Error Code: DependencyViolation.."

I ended up deleting the stack while skipping the deletion of some resources. Now the stack is deleted, and I have some resources that are not deleting due to dependencies. I have been trying to figure this out all day. Can anyone help?

These are the items that are not deleting:

2 VPCs - vpc-06b826b3ab1da2e58 // vpc-02de9af25da6ced01

2 subnets - subnet-0b672b0e8a1874a87 // subnet-0e4181e7a7537f251

2 network interfaces - "eni-00c5483e08913c88f" & "eni-061e8154b1bc16528"

2 security groups - "ecs-inf-test-servicesgE18B74B7-U32ANMY3D4J5" & "ecs-inf-test-servicesgE18B74B7-7U01IMREA0KK"

THANKS!

adub
asked 3 years ago570 views
3 Answers
0

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:

  1. 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

  1. 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

ayaar
answered 3 years ago
0

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"

adub
answered 3 years ago
0

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.
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions