Table Of Contents

Feedback

User Guide

First time using the AWS CLI? See the User Guide for help getting started.

[ aws . ec2 ]

describe-subnets

Description

Describes one or more of your subnets.

For more information, see Your VPC and Subnets in the Amazon Virtual Private Cloud User Guide .

See also: AWS API Documentation

See 'aws help' for descriptions of global parameters.

Synopsis

  describe-subnets
[--filters <value>]
[--subnet-ids <value>]
[--dry-run | --no-dry-run]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]

Options

--filters (list)

One or more filters.

  • availabilityZone - The Availability Zone for the subnet. You can also use availability-zone as the filter name.
  • available-ip-address-count - The number of IPv4 addresses in the subnet that are available.
  • cidrBlock - The IPv4 CIDR block of the subnet. The CIDR block you specify must exactly match the subnet's CIDR block for information to be returned for the subnet. You can also use cidr or cidr-block as the filter names.
  • defaultForAz - Indicates whether this is the default subnet for the Availability Zone. You can also use default-for-az as the filter name.
  • ipv6-cidr-block-association.ipv6-cidr-block - An IPv6 CIDR block associated with the subnet.
  • ipv6-cidr-block-association.association-id - An association ID for an IPv6 CIDR block associated with the subnet.
  • ipv6-cidr-block-association.state - The state of an IPv6 CIDR block associated with the subnet.
  • state - The state of the subnet (pending | available ).
  • subnet-id - The ID of the subnet.
  • tag :key- The key/value combination of a tag assigned to the resource. Use the tag key in the filter name and the tag value as the filter value. For example, to find all resources that have a tag with the key Owner and the value TeamA , specify tag:Owner for the filter name and TeamA for the filter value.
  • tag-key - The key of a tag assigned to the resource. Use this filter to find all resources assigned a tag with a specific key, regardless of the tag value.
  • vpc-id - The ID of the VPC for the subnet.

Shorthand Syntax:

Name=string,Values=string,string ...

JSON Syntax:

[
  {
    "Name": "string",
    "Values": ["string", ...]
  }
  ...
]

--subnet-ids (list)

One or more subnet IDs.

Default: Describes all your subnets.

Syntax:

"string" "string" ...

--dry-run | --no-dry-run (boolean)

Checks whether you have the required permissions for the action, without actually making the request, and provides an error response. If you have the required permissions, the error response is DryRunOperation . Otherwise, it is UnauthorizedOperation .

--cli-input-json (string) Performs service operation based on the JSON string provided. The JSON string follows the format provided by --generate-cli-skeleton. If other arguments are provided on the command line, the CLI values will override the JSON-provided values. It is not possible to pass arbitrary binary values using a JSON-provided value as the string will be taken literally.

--generate-cli-skeleton (string) Prints a JSON skeleton to standard output without sending an API request. If provided with no value or the value input, prints a sample input JSON that can be used as an argument for --cli-input-json. If provided with the value output, it validates the command inputs and returns a sample output JSON for that command.

See 'aws help' for descriptions of global parameters.

Examples

To describe your subnets

This example describes your subnets.

Command:

aws ec2 describe-subnets

Output:

{
    "Subnets": [
        {
            "VpcId": "vpc-a01106c2",
            "AvailableIpAddressCount": 251,
            "MapPublicIpOnLaunch": false,
            "DefaultForAz": false,
            "Ipv6CidrBlockAssociationSet": [],
            "State": "available",
            "AvailabilityZone": "us-east-1c",
            "SubnetId": "subnet-9d4a7b6c",
            "CidrBlock": "10.0.1.0/24",
            "AssignIpv6AddressOnCreation": false
        },
        {
          "VpcId": "vpc-31896b55",
          "AvailableIpAddressCount": 251,
          "MapPublicIpOnLaunch": false,
          "DefaultForAz": false,
          "Ipv6CidrBlockAssociationSet": [
              {
                  "Ipv6CidrBlock": "2001:db8:1234:a101::/64",
                  "AssociationId": "subnet-cidr-assoc-30e7e348",
                  "Ipv6CidrBlockState": {
                      "State": "ASSOCIATED"
                  }
              }
          ],
          "State": "available",
          "AvailabilityZone": "us-east-1a",
          "SubnetId": "subnet-4204d234",
          "CidrBlock": "10.0.1.0/24",
          "AssignIpv6AddressOnCreation": false
      }
    ]
}

To describe the subnets for a specific VPC

This example describes the subnets for the specified VPC.

Command:

aws ec2 describe-subnets --filters "Name=vpc-id,Values=vpc-a01106c2"

To describe subnets with a specific tag

This example lists subnets with the tag Name=MySubnet and returns the output in text format.

Command:

aws ec2 describe-subnets --filters Name=tag:Name,Values=MySubnet --output text

Output:

SUBNETS       False   us-east-1a      251     10.0.1.0/24     False   False   available       subnet-5f46ec3b vpc-a034d6c4
TAGS  Name    MySubnet

Output

Subnets -> (list)

Information about one or more subnets.

(structure)

Describes a subnet.

AvailabilityZone -> (string)

The Availability Zone of the subnet.

AvailableIpAddressCount -> (integer)

The number of unused private IPv4 addresses in the subnet. The IPv4 addresses for any stopped instances are considered unavailable.

CidrBlock -> (string)

The IPv4 CIDR block assigned to the subnet.

DefaultForAz -> (boolean)

Indicates whether this is the default subnet for the Availability Zone.

MapPublicIpOnLaunch -> (boolean)

Indicates whether instances launched in this subnet receive a public IPv4 address.

State -> (string)

The current state of the subnet.

SubnetId -> (string)

The ID of the subnet.

VpcId -> (string)

The ID of the VPC the subnet is in.

AssignIpv6AddressOnCreation -> (boolean)

Indicates whether a network interface created in this subnet (including a network interface created by RunInstances ) receives an IPv6 address.

Ipv6CidrBlockAssociationSet -> (list)

Information about the IPv6 CIDR blocks associated with the subnet.

(structure)

Describes an IPv6 CIDR block associated with a subnet.

AssociationId -> (string)

The association ID for the CIDR block.

Ipv6CidrBlock -> (string)

The IPv6 CIDR block.

Ipv6CidrBlockState -> (structure)

Information about the state of the CIDR block.

State -> (string)

The state of a CIDR block.

StatusMessage -> (string)

A message about the status of the CIDR block, if applicable.

Tags -> (list)

Any tags assigned to the subnet.

(structure)

Describes a tag.

Key -> (string)

The key of the tag.

Constraints: Tag keys are case-sensitive and accept a maximum of 127 Unicode characters. May not begin with aws:

Value -> (string)

The value of the tag.

Constraints: Tag values are case-sensitive and accept a maximum of 255 Unicode characters.