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






Are you looking for a Disqus alternative?

You should check out my latest project, Remarkbox. It's a comment system that works everywhere, even static sites!

Remarks: Boto3 get main route table

© Russell Ballestrini.