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:
    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. : )

Looking for a better comment system?

You should try Remarkbox — a hosted comment service that embeds in your pages to keep the conversation in the same place as your content. It works everywhere, even static sites!

Remarks: Boto3 get main route table

© Russell Ballestrini.