无法获取路由表附加的资源

时间:2016-09-12 19:30:14

标签: python amazon-web-services amazon-ec2 boto3 botocore

我正在使用python进行AWS基础架构自动化。 我需要获得路由表附带的资源,其中给出的API是

ec2  = boto3.resource('ec2')
route_table_association = ec2.RouteTableAssociation('rtb-**********')
response=route_table_association.get_available_subresources()

这里的响应返回类型一直给我空列表。并且response=route_table_association.delete()给出例外

An error occurred (InvalidAssociationID.NotFound) when calling the `DisassociateRouteTable operation: The association ID 'rtb-*********' does not exist.`

但路由tebale存在并明确附加到子网

2 个答案:

答案 0 :(得分:0)

所需的ID为RouteTableAssociationId i.e. rtbassoc-xxxxxx 不是路线表ID

RouteTableAssociationId位于describe_route_tables响应JSON'Associations'元素内。

{
    'RouteTables': [
        {
            'RouteTableId': 'string',
            'VpcId': 'string',
            'Routes': [
                {....}
            ],
            'Associations': [
                {
                    'RouteTableAssociationId': 'string',
                    'RouteTableId': 'string',
                    'SubnetId': 'string',
                    'Main': True|False
                },
            ],
.....
}

答案 1 :(得分:0)

谢谢这对我有用。

response = client.describe_route_tables(
    RouteTableIds=[
        routetable,
    ],
    Filters=[
        {
            'Name': 'route-table-id',
            'Values': [
                routetable
            ]
        }
    ]
)