Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find unused VPC in AWS account

Is there any way to find unused VPCs in an AWS account?

I mean the VPCs that don't have any EC2 instances, RDS and other services associated with it.

One way is to just search with VPC ID in running instances, RDS and for other services to find out whether it is in use or not. Is there any other way or AWS CLI to find unused VPCs?

like image 781
MichealMills Avatar asked Oct 14 '16 07:10

MichealMills


People also ask

How many VPCs Can an AWS account have?

By default you can create up to 5 VPCs. You can ask for additional VPCs using the VPC Request Limit Increase form. You can now check the status of each of your VPN Connections from the command line or from the VPC tab of the AWS Management Console.

Does each AWS account have a VPC?

VPC sharing is only available within the same AWS Organization. Sharing of default VPCs/subnets is not possible. Participants can't launch resources using security groups that are owned by other participants or the owner.


1 Answers

There are many resources that be included in a VPC, such as:

  • Amazon EC2 instances
  • Amazon RDS instances
  • Amazon Redshift instances
  • Amazon Elasticache instances
  • Elastic Load Balancers
  • Elastic Network Interfaces
  • and so on!

Rather than trying to iterate through each of these services, you could iterate through the Elastic Network Interfaces (ENIs), since everything connects to a VPC via an ENI.

Here's a command you could run using the AWS Command-Line Interface (CLI) that shows ENIs attached to a given VPC:

aws ec2 describe-network-interfaces --filters 'Name=vpc-id,Values=vpc-abcd1234' --query 'NetworkInterfaces[*].NetworkInterfaceId'

If no ENIs are returned, then you'd probably call it an unused VPC.

like image 188
John Rotenstein Avatar answered Sep 27 '22 22:09

John Rotenstein