- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
DescribeSubnetsCommand
Describes your subnets. The default is to describe all your subnets. Alternatively, you can specify specific subnet IDs or filter the results to include only the subnets that match specific criteria.
For more information, see Subnets in the Amazon VPC User Guide.
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { EC2Client, DescribeSubnetsCommand } from "@aws-sdk/client-ec2"; // ES Modules import
// const { EC2Client, DescribeSubnetsCommand } = require("@aws-sdk/client-ec2"); // CommonJS import
const client = new EC2Client(config);
const input = { // DescribeSubnetsRequest
Filters: [ // FilterList
{ // Filter
Name: "STRING_VALUE",
Values: [ // ValueStringList
"STRING_VALUE",
],
},
],
SubnetIds: [ // SubnetIdStringList
"STRING_VALUE",
],
NextToken: "STRING_VALUE",
MaxResults: Number("int"),
DryRun: true || false,
};
const command = new DescribeSubnetsCommand(input);
const response = await client.send(command);
// { // DescribeSubnetsResult
// NextToken: "STRING_VALUE",
// Subnets: [ // SubnetList
// { // Subnet
// AvailabilityZoneId: "STRING_VALUE",
// EnableLniAtDeviceIndex: Number("int"),
// MapCustomerOwnedIpOnLaunch: true || false,
// CustomerOwnedIpv4Pool: "STRING_VALUE",
// OwnerId: "STRING_VALUE",
// AssignIpv6AddressOnCreation: true || false,
// Ipv6CidrBlockAssociationSet: [ // SubnetIpv6CidrBlockAssociationSet
// { // SubnetIpv6CidrBlockAssociation
// AssociationId: "STRING_VALUE",
// Ipv6CidrBlock: "STRING_VALUE",
// Ipv6CidrBlockState: { // SubnetCidrBlockState
// State: "associating" || "associated" || "disassociating" || "disassociated" || "failing" || "failed",
// StatusMessage: "STRING_VALUE",
// },
// Ipv6AddressAttribute: "public" || "private",
// IpSource: "amazon" || "byoip" || "none",
// },
// ],
// Tags: [ // TagList
// { // Tag
// Key: "STRING_VALUE",
// Value: "STRING_VALUE",
// },
// ],
// SubnetArn: "STRING_VALUE",
// OutpostArn: "STRING_VALUE",
// EnableDns64: true || false,
// Ipv6Native: true || false,
// PrivateDnsNameOptionsOnLaunch: { // PrivateDnsNameOptionsOnLaunch
// HostnameType: "ip-name" || "resource-name",
// EnableResourceNameDnsARecord: true || false,
// EnableResourceNameDnsAAAARecord: true || false,
// },
// BlockPublicAccessStates: { // BlockPublicAccessStates
// InternetGatewayBlockMode: "off" || "block-bidirectional" || "block-ingress",
// },
// SubnetId: "STRING_VALUE",
// State: "pending" || "available" || "unavailable",
// VpcId: "STRING_VALUE",
// CidrBlock: "STRING_VALUE",
// AvailableIpAddressCount: Number("int"),
// AvailabilityZone: "STRING_VALUE",
// DefaultForAz: true || false,
// MapPublicIpOnLaunch: true || false,
// },
// ],
// };
Example Usage
DescribeSubnetsCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
DryRun | boolean | undefined | 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 |
Filters | Filter[] | undefined | The filters.
|
MaxResults | number | undefined | The maximum number of items to return for this request. To get the next page of items, make another request with the token returned in the output. For more information, see Pagination . |
NextToken | string | undefined | The token returned from a previous paginated request. Pagination continues from the end of the items returned by the previous request. |
SubnetIds | string[] | undefined | The IDs of the subnets. Default: Describes all your subnets. |
DescribeSubnetsCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
NextToken | string | undefined | The token to include in another request to get the next page of items. This value is |
Subnets | Subnet[] | undefined | Information about the subnets. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
EC2ServiceException | Base exception class for all service exceptions from EC2 service. |