与 AWS SDK或DescribeRouteTables一起使用 CLI - AWS SDK代码示例

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

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

与 AWS SDK或DescribeRouteTables一起使用 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
SDK for PHP
注意

还有更多相关信息 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中的。