See all resources in a subnet / See if subnet is in use
Solution 1:
aws ec2 describe-network-interfaces --filters Name=subnet-id,Values=subnet-id-here | grep Description
(replace subnet-id-here
with the subnet id in mind)
The above command will give you the names of resources in that subnet.
Solution 2:
Take a look at aws ec2 describe-network-interfaces
.
This returns a list of Elastic Network Interfaces (ENIs) and supports a subnet-id
filter. EC2 instances aren't the only thing that can be on a subnet -- RDS instances, Elastic Load Balancers, Lambda functions, Elastic File System mount targets, NAT Gateways, and other resources consume IP addresses on a subnet, but in each case I can think of, they do this by allocating ENIs. In some cases, like load balancers (ALB and Classic), the number of addresses grows and shrinks as the balancer scales up and down in capacity. In the case of Lambda, a lack of allocated ENIs may only mean that no Lambda container hosts are currently using the subnet, due to a lack of traffic... so if you have VPC Lambda functions, bear that in mind.
You can also see ENIs in the EC2 console, under "Network Interfaces" in the left hand navigation pane.