Boto3 get main route table

This entry is part 6 of 6 in the series Boto
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]
Series NavigationA Python script which searches for available interpreters

Leave a Reply

Your email address will not be published. Required fields are marked *