Random   •   Archives   •   RSS   •   About   •   Contact

Boto3 get main route table

While developing Botoform I ran into an issue with Boto3 where I couldn't easily get the "main" route table of a VPC. I ended up adding a get_main_route_table method to do the duty.

def get_main_route_table(self):
    """Return the main (default) route table for VPC."""
    main_route_table = []
    for route_table in list(self.route_tables.all()):
        for association in list(route_table.associations.all()):
            if association.main == True:
                main_route_table.append(route_table)
    if len(main_route_table) != 1:
        raise Exception('cannot get main route table! {}'.format(main_route_table))
    return main_route_table[0]

That all for now!

You should read my other Boto related posts for tricks to impress your friends. : )




Want comments on your site?

Remarkbox — is a free SaaS comment service which embeds into your pages to keep the conversation in the same place as your contentr. It works everywhere, even static HTML sites like this one!

Remarks: Boto3 get main route table

© Russell Ballestrini.