Getting Information About Your Subnets

You can get information about one or more of your subnets, like the Virtual Private Cloud (VPC) in which they are, their CIDR block or their Availability Zone (AZ).

If you exceed the number of identical requests allowed for a configured time period, the RequestLimitExceeded error message is returned.

This procedure uses AWS CLI only. Information about your subnets is also available:

To get information about one or more of your subnets, use the describe-subnets command following this syntax:

Request sample
$ aws ec2 describe-subnets \
    --profile YOUR_PROFILE \
    [--subnet-ids NOT_SPECIFIED]\
    --filters [
               {
                "Name": "vpc-id",
                "Values": "vpc-12345678"
               },
               {
                "Name": "state",
                "Values": "available"
               }
             ] \
    --endpoint https://fcu.eu-west-2.outscale.com

This command contains the following attributes that you need to specify:

  • (optional) profile: The named profile you want to use, created when configuring AWS CLI. For more information, see Installing and Configuring AWS CLI.

  • (optional) subnet-ids: One or more IDs of subnets.

    If you do not specify any subnet ID, all your subnets or all the subnets matching the specified filters (if any) are described.

  • (optional) filters: One or more filters, in the "Name=X,Values=Y" format.

    You can specify several values for a same filter using the "Name=X,Values=Y, Z" format.

    The following filters are available:

    • subnet-id: The ID of the subnet.

    • vpc-id: The ID of the VPC in which the subnet is.

    • state: The state of the subnet (pending | available). For more information, see About VPCs.

    • cidr: The exact CIDR block of the subnet (similar to cidr-block).

    • cidr-block: The exact CIDR block of the subnet (similar to cidr).

    • available-ip-address-count: The number of available IPs in the subnet.

    • availability-zone: The AZ in which the subnets are located.

  • endpoint: The endpoint corresponding to the Region you want to send the request to.

The describe-subnets command returns the following elements:

  • Subnets: Information about one or more subnets. This element contains the following information:

    • VpcId: The VPC in which the subnet is.

    • CidrBlock: The range of IPs for the subnet, in CIDR notation.

    • State: The state of the VPC. For more information, see About VPCs.

    • AvailabilityZone: The AZ in which the subnet is.

    • SubnetId: The ID of the subnet.

    • AvailableIpAddressCount: The number of unused IPs in the subnet.

    • MapPublicIpOnLaunch: Specifies whether a public IP is assigned to the instances launched in the subnet.

Result sample
{
    "Subnets": [
        {
            "VpcId": "vpc-12345678",
            "CidrBlock": "10.0.1.0/24",
            "State": "available",
            "AvailabilityZone": "eu-west-2a",
            "SubnetId": "subnet-1234abcd",
            "AvailableIpAddressCount": 242,
            "MapPublicIpOnLaunch": false
        },
        {
            "VpcId": "vpc-12345678",
            "CidrBlock": "10.0.2.0/24",
            "State": "available",
            "AvailabilityZone": "eu-west-2b",
            "SubnetId": "subnet-4321dcba",
            "AvailableIpAddressCount": 243,
            "MapPublicIpOnLaunch": false
        }
    ]
}

Related Pages

Corresponding API Method

AWS™ and Amazon Web Services™ are trademarks of Amazon Technologies, Inc or its affiliates in the United States and/or other countries.