0

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?

0

One option is to retrieve the mapping from the instances instead - e.g.

$ aws ec2 describe-instances | grep subnet
                "SubnetId": "<subnet_id>",
                        "SubnetId": "<subnet_id>",
                "SubnetId": "<subnet_id>",
                        "SubnetId": "<subnet_id>",
                "SubnetId": "<subnet_id>",
                        "SubnetId": "<subnet_id>",
                ...

That seems pretty kludgy - since amazon already maintains this mapping, why can't they expose it with the subnet id as the key instead of the instance? Or am I missing something here?

0

Here is an example with a querry for two subnets.

aws ec2 describe-instances --filters 'Name=subnet-id,Values=[subnet-12345678,subnet-90abcdef]'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.