选择您的 Cookie 首选项

我们使用必要 Cookie 和类似工具提供我们的网站和服务。我们使用性能 Cookie 收集匿名统计数据,以便我们可以了解客户如何使用我们的网站并进行改进。必要 Cookie 无法停用,但您可以单击“自定义”或“拒绝”来拒绝性能 Cookie。

如果您同意,AWS 和经批准的第三方还将使用 Cookie 提供有用的网站功能、记住您的首选项并显示相关内容,包括相关广告。要接受或拒绝所有非必要 Cookie,请单击“接受”或“拒绝”。要做出更详细的选择,请单击“自定义”。

DescribeRouteTables与 AWS SDK 或 CLI 配合使用 - AWS SDK 代码示例

文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

文档 AWS SDK 示例 GitHub 存储库中还有更多 S AWS DK 示例

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

DescribeRouteTables与 AWS SDK 或 CLI 配合使用

以下代码示例演示如何使用 DescribeRouteTables

CLI
AWS CLI

描述路由表

以下 describe-route-tables 示例检索有关路由表的详细信息。

aws ec2 describe-route-tables

输出:

{ "RouteTables": [ { "Associations": [ { "Main": true, "RouteTableAssociationId": "rtbassoc-0df3f54e06EXAMPLE", "RouteTableId": "rtb-09ba434c1bEXAMPLE" } ], "PropagatingVgws": [], "RouteTableId": "rtb-09ba434c1bEXAMPLE", "Routes": [ { "DestinationCidrBlock": "10.0.0.0/16", "GatewayId": "local", "Origin": "CreateRouteTable", "State": "active" }, { "DestinationCidrBlock": "0.0.0.0/0", "NatGatewayId": "nat-06c018cbd8EXAMPLE", "Origin": "CreateRoute", "State": "blackhole" } ], "Tags": [], "VpcId": "vpc-0065acced4EXAMPLE", "OwnerId": "111122223333" }, { "Associations": [ { "Main": true, "RouteTableAssociationId": "rtbassoc-9EXAMPLE", "RouteTableId": "rtb-a1eec7de" } ], "PropagatingVgws": [], "RouteTableId": "rtb-a1eec7de", "Routes": [ { "DestinationCidrBlock": "172.31.0.0/16", "GatewayId": "local", "Origin": "CreateRouteTable", "State": "active" }, { "DestinationCidrBlock": "0.0.0.0/0", "GatewayId": "igw-fEXAMPLE", "Origin": "CreateRoute", "State": "active" } ], "Tags": [], "VpcId": "vpc-3EXAMPLE", "OwnerId": "111122223333" }, { "Associations": [ { "Main": false, "RouteTableAssociationId": "rtbassoc-0b100c28b2EXAMPLE", "RouteTableId": "rtb-07a98f76e5EXAMPLE", "SubnetId": "subnet-0d3d002af8EXAMPLE" } ], "PropagatingVgws": [], "RouteTableId": "rtb-07a98f76e5EXAMPLE", "Routes": [ { "DestinationCidrBlock": "10.0.0.0/16", "GatewayId": "local", "Origin": "CreateRouteTable", "State": "active" }, { "DestinationCidrBlock": "0.0.0.0/0", "GatewayId": "igw-06cf664d80EXAMPLE", "Origin": "CreateRoute", "State": "active" } ], "Tags": [], "VpcId": "vpc-0065acced4EXAMPLE", "OwnerId": "111122223333" } ] }

有关更多信息,请参阅《AWS VPC 用户指南》中的使用路由表

PHP
适用于 PHP 的 SDK
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

/** * @param array $routeTableIds * @param array $filters * @return array */ public function describeRouteTables(array $routeTableIds = [], array $filters = []): array { $parameters = []; if($routeTableIds){ $parameters['RouteTableIds'] = $routeTableIds; } if($filters){ $parameters['Filters'] = $filters; } try { $paginator = $this->ec2Client->getPaginator("DescribeRouteTables", $parameters); $contents = []; foreach ($paginator as $result) { foreach ($result['RouteTables'] as $object) { $contents[] = $object['RouteTableId']; } } }catch (Ec2Exception $caught){ echo "There was a problem paginating the results of DescribeRouteTables: {$caught->getAwsErrorMessage()}\n"; throw $caught; } return $contents; }
  • 有关 API 的详细信息,请参阅 AWS SDK for PHP API 参考DescribeRouteTables中的。

PowerShell
用于 PowerShell

示例 1:此示例描述了您的所有路由表。

Get-EC2RouteTable

输出

DestinationCidrBlock : 10.0.0.0/16 DestinationPrefixListId : GatewayId : local InstanceId : InstanceOwnerId : NetworkInterfaceId : Origin : CreateRouteTable State : active VpcPeeringConnectionId : DestinationCidrBlock : 0.0.0.0/0 DestinationPrefixListId : GatewayId : igw-1a2b3c4d InstanceId : InstanceOwnerId : NetworkInterfaceId : Origin : CreateRoute State : active VpcPeeringConnectionId :

示例 2:此示例返回指定路由表的详细信息。

Get-EC2RouteTable -RouteTableId rtb-1a2b3c4d

示例 3:此示例描述了指定 VPC 的路由表。

Get-EC2RouteTable -Filter @{ Name="vpc-id"; Values="vpc-1a2b3c4d" }

输出

Associations : {rtbassoc-12345678} PropagatingVgws : {} Routes : {, } RouteTableId : rtb-1a2b3c4d Tags : {} VpcId : vpc-1a2b3c4d
  • 有关 API 的详细信息,请参阅 AWS Tools for PowerShell Cmdlet 参考DescribeRouteTables中的。

Python
适用于 Python 的 SDK(Boto3)
注意

还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库中进行设置和运行。

class VpcWrapper: """Encapsulates Amazon Elastic Compute Cloud (Amazon EC2) Amazon Virtual Private Cloud actions.""" def __init__(self, ec2_client: boto3.client): """ Initializes the VpcWrapper with an EC2 client. :param ec2_client: A Boto3 Amazon EC2 client. This client provides low-level access to AWS EC2 services. """ self.ec2_client = ec2_client @classmethod def from_client(cls) -> "VpcWrapper": """ Creates a VpcWrapper instance with a default EC2 client. :return: An instance of VpcWrapper initialized with the default EC2 client. """ ec2_client = boto3.client("ec2") return cls(ec2_client) def describe_route_tables(self, vpc_ids: list[str]) -> None: """ Displays information about the route tables in the specified VPC. :param vpc_ids: A list of VPC IDs. """ try: response = self.ec2_client.describe_route_tables( Filters=[{"Name": "vpc-id", "Values": vpc_ids}] ) pp(response["RouteTables"]) except ClientError as err: logger.error( "Couldn't describe route tables for VPCs %s. Here's why: %s: %s", vpc_ids, err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
  • 有关 API 的详细信息,请参阅适用DescribeRouteTablesPython 的AWS SDK (Boto3) API 参考

AWS CLI

描述路由表

以下 describe-route-tables 示例检索有关路由表的详细信息。

aws ec2 describe-route-tables

输出:

{ "RouteTables": [ { "Associations": [ { "Main": true, "RouteTableAssociationId": "rtbassoc-0df3f54e06EXAMPLE", "RouteTableId": "rtb-09ba434c1bEXAMPLE" } ], "PropagatingVgws": [], "RouteTableId": "rtb-09ba434c1bEXAMPLE", "Routes": [ { "DestinationCidrBlock": "10.0.0.0/16", "GatewayId": "local", "Origin": "CreateRouteTable", "State": "active" }, { "DestinationCidrBlock": "0.0.0.0/0", "NatGatewayId": "nat-06c018cbd8EXAMPLE", "Origin": "CreateRoute", "State": "blackhole" } ], "Tags": [], "VpcId": "vpc-0065acced4EXAMPLE", "OwnerId": "111122223333" }, { "Associations": [ { "Main": true, "RouteTableAssociationId": "rtbassoc-9EXAMPLE", "RouteTableId": "rtb-a1eec7de" } ], "PropagatingVgws": [], "RouteTableId": "rtb-a1eec7de", "Routes": [ { "DestinationCidrBlock": "172.31.0.0/16", "GatewayId": "local", "Origin": "CreateRouteTable", "State": "active" }, { "DestinationCidrBlock": "0.0.0.0/0", "GatewayId": "igw-fEXAMPLE", "Origin": "CreateRoute", "State": "active" } ], "Tags": [], "VpcId": "vpc-3EXAMPLE", "OwnerId": "111122223333" }, { "Associations": [ { "Main": false, "RouteTableAssociationId": "rtbassoc-0b100c28b2EXAMPLE", "RouteTableId": "rtb-07a98f76e5EXAMPLE", "SubnetId": "subnet-0d3d002af8EXAMPLE" } ], "PropagatingVgws": [], "RouteTableId": "rtb-07a98f76e5EXAMPLE", "Routes": [ { "DestinationCidrBlock": "10.0.0.0/16", "GatewayId": "local", "Origin": "CreateRouteTable", "State": "active" }, { "DestinationCidrBlock": "0.0.0.0/0", "GatewayId": "igw-06cf664d80EXAMPLE", "Origin": "CreateRoute", "State": "active" } ], "Tags": [], "VpcId": "vpc-0065acced4EXAMPLE", "OwnerId": "111122223333" } ] }

有关更多信息,请参阅《AWS VPC 用户指南》中的使用路由表

隐私网站条款Cookie 首选项
© 2025, Amazon Web Services, Inc. 或其附属公司。保留所有权利。