AWS: How do I find the list of instances associated with a particular subnet?
AWS now creates a default VPC and default subnet(s) for every instance launched. http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/default-vpc.html
You see the list of subnets either through the UI, or through the CLI
$ aws ec2 describe-subnets
{
"Subnets": [
...
]
}
But the information on each subnet does not contain the list of instances associated with it.
{
"AvailabilityZone": "us-east-1d",
"AvailableIpAddressCount": 251,
"CidrBlock": "172.30.2.0/24",
"DefaultForAz": false,
"MapPublicIpOnLaunch": true,
"State": "available",
"SubnetId": "<subnet_id>",
"VpcId": "<vpc_id>",
"AssignIpv6AddressOnCreation": false,
"Ipv6CidrBlockAssociationSet": []
},
How do I get the list of instances associated with a subnet?
Solution 1:
Here is an example with a querry for two subnets.
aws ec2 describe-instances --filters 'Name=subnet-id,Values=[subnet-12345678,subnet-90abcdef]'