【问题标题】:AWS API - How to get main route table ID by subnet ID? association.subnet-id filter doesn't workAWS API - 如何通过子网 ID 获取主路由表 ID? Association.subnet-id 过滤器不起作用
【发布时间】: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,然后获取其主路由表?
  • 谢谢,我错误地假设每个子网都有隐式主路由表,这是不正确的。我已根据您的帮助添加了答案。

标签: amazon-web-services


【解决方案1】:

我错误地认为 VPC 中有多个主子网。

鉴于 VPC 中只有一个主子网,以下是获取主表路由 ID 的方法: aws ec2 describe-route-tables --filters "Name=association.main,Values=true" "Name=vpc-id,Values=&lt;vpc-id&gt;" --query=RouteTables[*].RouteTableId --output=text

【讨论】:

    猜你喜欢
    • 2021-04-26
    • 2019-08-15
    • 2021-03-25
    • 1970-01-01
    • 1970-01-01
    • 2014-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多