diff --git a/octodns/provider/route53.py b/octodns/provider/route53.py index 2bf59a5..cd0b720 100644 --- a/octodns/provider/route53.py +++ b/octodns/provider/route53.py @@ -669,11 +669,12 @@ class Route53Provider(BaseProvider): response = self._conn.list_hosted_zones_by_name( DNSName=name, MaxItems="1" ) - if len(response['HostedZones']) == 1: - # if there is a single response - id = response['HostedZones'][0]['Id'] - self.log.debug(id) - return id + if len(response['HostedZones']) != 0: + # if there is a response that starts with the name + if response['HostedZones'][0]['Name'].startswith(name): + id = response['HostedZones'][0]['Id'] + self.log.debug('get_zones_by_name: id=%s', id) + return id elif name in self.r53_zones: id = self.r53_zones[name] self.log.debug('_get_zone_id: id=%s', id) diff --git a/tests/test_octodns_provider_route53.py b/tests/test_octodns_provider_route53.py index 136f442..4b3b759 100644 --- a/tests/test_octodns_provider_route53.py +++ b/tests/test_octodns_provider_route53.py @@ -1782,6 +1782,43 @@ class TestRoute53Provider(TestCase): self.assertEquals([], extra) stubber.assert_no_pending_responses() + def test_zone_not_found_get_zones_by_name(self): + provider = Route53Provider( + 'test', 'abc', '123', get_zones_by_name=True) + + # Use the stubber + stubber = Stubber(provider._conn) + stubber.activate() + + list_hosted_zones_by_name_resp = { + 'HostedZones': [{ + 'Id': 'z43', + 'Name': 'bad.tests.', + 'CallerReference': 'abc', + 'Config': { + 'Comment': 'string', + 'PrivateZone': False + }, + 'ResourceRecordSetCount': 123, + }, ], + 'DNSName': 'unit.tests.', + 'HostedZoneId': 'z42', + 'IsTruncated': False, + 'MaxItems': 'string' + } + + stubber.add_response( + 'list_hosted_zones_by_name', + list_hosted_zones_by_name_resp, + {'DNSName': 'unit.tests.', 'MaxItems': '1'} + ) + + # empty is empty + desired = Zone('unit.tests.', []) + extra = provider._extra_changes(desired=desired, changes=[]) + self.assertEquals([], extra) + stubber.assert_no_pending_responses() + def test_plan_with_get_zones_by_name(self): provider = Route53Provider( 'test', 'abc', '123', get_zones_by_name=True)