'Find the zone id responsible a given FQDN.
That is, the id for the zone whose name is the longest parent of the
domain.'

def _find_zone_id_for_domain(self, domain):

    paginator = self.r53.get_paginator('list_hosted_zones')
    zones = []
    target_labels = domain.rstrip('.').split('.')
    for page in paginator.paginate():
        for zone in page['HostedZones']:
            if zone['Config']['PrivateZone']:
                continue
            candidate_labels = zone['Name'].rstrip('.').split('.')
            if (candidate_labels == target_labels[(- len(candidate_labels)):]):
                zones.append((zone['Name'], zone['Id']))
    if (not zones):
        raise errors.PluginError('Unable    to    find    a    Route53    hosted    zone    for    {0}'.format(domain))
    zones.sort(key=(lambda z: len(z[0])), reverse=True)
    return zones[0][1]
