- Newest
- Most votes
- Most comments
Have a good look at the documentation for the commands you're running. For example if you type "aws ec2 disassociate-route-table help" you'll see what parameters it's expecting. "--association-id" does not expect a subnet ID.
If you're not up to speed with the CLI, and this isn't something you need to do many times, why not use the console to delete what you need to?
Here are some examples of deleting VPC components and the VPC. I'm using tags as the filter, change to whatever you need.
Delete route table/subnet association.
aws ec2 disassociate-route-table \
--association-id \
$(aws ec2 describe-route-tables \
--output text \
--query "RouteTables[*].Associations[?SubnetId==\`\
$(aws ec2 describe-subnets \
--output text \
--query "Subnets[0].SubnetId" \
--filters "Name=tag:Name,Values=public-subnet")\`].RouteTableAssociationId" \
--filters "Name=tag:Name,Values=public-route-table" \)
Delete route
aws ec2 delete-route \
--destination-cidr-block "0.0.0.0/0" \
--route-table-id \
$(aws ec2 describe-route-tables \
--output text \
--query "RouteTables[0].RouteTableId" \
--filters "Name=tag:Name,Values=public-route-table")
Delete Route table
aws ec2 delete-route-table \
--route-table-id \
$(aws ec2 describe-route-tables \
--output text \
--query "RouteTables[0].RouteTableId" \
--filters "Name=tag:Name,Values=public-route-table")
Detach and delete internet gateway
aws ec2 detach-internet-gateway \
--internet-gateway-id \
$(aws ec2 describe-internet-gateways \
--filters "Name=tag:Name,Values=internet-gateway" \
--output text \
--query "InternetGateways[0].InternetGatewayId") \
--vpc-id \
$(aws ec2 describe-vpcs \
--filters "Name=tag:Name,Values=vpc" \
--output text \
--query "Vpcs[0].VpcId")
aws ec2 delete-internet-gateway \
--internet-gateway-id \
$(aws ec2 describe-internet-gateways \
--filters "Name=tag:Name,Values=internet-gateway" \
--output text \
--query "InternetGateways[0].InternetGatewayId")
Delete subnet
aws ec2 delete-subnet \
--subnet-id \
$(aws ec2 describe-subnets \
--filters "Name=tag:Name,Values=public-subnet" \
--output text \
--query "Subnets[0].SubnetId")
Delete VPC
aws ec2 delete-vpc \
--vpc-id \
$(aws ec2 describe-vpcs \
--filters "Name=tag:Name,Values=vpc" \
--output text \
--query "Vpcs[0].VpcId")
If you have Network Interfaces that prevent deleting the VPC, you will need to find whatever that is an delete them first.
Those Network Interfaces are not getting deleted also security rules are also not getting deleted. I will try you code replaced with name in Name and let you know.
Run this command to get an idea of what the ENIs are used for.
aws ec2 describe-network-interfaces --query NetworkInterfaces[*].Description
It looks like maybe you're running a bash script (I see '#!/bin/bash' as the first command) and inside their you're setting a region of ap-southeast-1, so you're returning information about your assets in that region. But after the script terminates, what region do you have set? Probably a different one as you can't seem to delete the assets your script reported.
Thank you for bringing my attention to it, I have updated code to set region but getting errors in different way.
I'm having a similar problem and I've narrowed it down to a mysterious user account ID attached to a network adapter and no such user exists. I get errors telling me that I lack the permissions to remove it despite running through both an admin account and as root. I'm the only user on this account so it's not like someone else attached a network adapter to a running machine built by me. I didn't create an account, attach a network interface, and delete the account - which even if I did, it should then automatically revert to me as root. So whatever the issue is, I'm stumped. I'm of no help to you except to say that you aren't alone. lol
Relevant content
- asked a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated a year ago
Dependency are in dependency are in deadlock. the console does not help. It is like billing ghost to me. dependency check says they are therefore but deleting commands do not found any.
I am using aws cloud shell and commands are ok. there is no syntax error.
No, there's no syntax errors but there are semantic errors. Maybe I wasn't clear - you are calling "aws ec2 disassociate-route-table --association-id subnet-0a4876918e50d2133" but this won't work, as you need to pass an Association ID, not a Subnet ID. BTW if you're deleting these resources because you're worried about being billed for them, note they don't cost anything.