【发布时间】:2021-03-12 12:22:25
【问题描述】:
我需要获取子网主路由表的 ID,以便添加更多路由。 该路由表是隐式关联的(因此是主要的)。
我正在使用:aws ec2 describe-route-tables 与此过滤器:--filters "Name=association.subnet-id,Values=<subnet_id>" 但是此过滤器仅适用于显式关联。
我可以使用:association.main 过滤器,但是在我的 VPC 中,我有多个主路由表,所以这在我的情况下不起作用。
更新:以上陈述不正确,因此是我的麻烦来源
文档:https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-route-tables.html
"如果子网没有与任何路由表显式关联,则它是 与主路由表隐式关联。该命令不 返回隐式关联的子网 ID。"
有什么解决办法吗?
当我手动获取路由表 ID(使用 Web 界面)时,我可以很好地检索它:--filters "Name=association.route-table-id,Values=rtb-<>":
{
"RouteTables": [
{
"Associations": [
{
"Main": true,
"RouteTableAssociationId": "rtbassoc-<>",
"RouteTableId": "rtb-<>",
"AssociationState": {
"State": "associated"
}
}
],
"PropagatingVgws": [],
"RouteTableId": "rtb-<>",
"Routes": [
{
"DestinationCidrBlock": "10.109.0.0/16",
"GatewayId": "local",
"Origin": "CreateRouteTable",
"State": "active"
}
],
"Tags": [
{
"Key": "Name",
"Value": ""
}
],
"VpcId": "vpc-<>",
"OwnerId": "<>"
}
]
}
只是我需要通过API方式获取路由表id,而不是web接口。
【问题讨论】:
-
每个vpc只有1个主路由表对,你有vpc id来获取它的路由表吗?如果没有,获取给定子网的vpc,然后获取其主路由表?
-
谢谢,我错误地假设每个子网都有隐式主路由表,这是不正确的。我已根据您的帮助添加了答案。