Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AWS Route 53 with Boto: alias target name does not lie within the target zone

I am trying to update existing alias_dns_name to different new elb using python boto '2.38.0'

def a_record_alias_update(myRegion, myDomain, elbName, elbZone):
dnsConn = route53.connect_to_region(myRegion)
myZone = dnsConn.get_zone(myDomain+'.')
changes = route53.record.ResourceRecordSets(dnsConn,myZone.id)
add_change_args_upsert = {
    'action': 'UPSERT',
    'name': 'dev.'+myDomain+'.',
    'type': 'A',
    'alias_hosted_zone_id': elbZone,
    'alias_dns_name': elbName,
    'alias_evaluate_target_health': True
}
change = changes.add_change(**add_change_args_upsert)
result = changes.commit()
return result

Error:

result = changes.commit()
File "/Library/Python/2.7/site-packages/boto/route53/record.py", line 168, in commit
return self.connection.change_rrsets(self.hosted_zone_id, self.to_xml())
File "/Library/Python/2.7/site-packages/boto/route53/connection.py", line 475, in change_rrsets
body)
boto.route53.exception.DNSServerError: DNSServerError: 400 Bad Request
<?xml version="1.0"?>
<ErrorResponse xmlns="https://route53.amazonaws.com/doc/2013-04-01/"><Error>    <Type>Sender</Type><Code>InvalidChangeBatch</Code><Message>Tried to create an alias that targets <alias_dns_name>., type A in zone <alias_hosted_zone_id>, but the alias target name does not lie within the target zone</Message></Error><RequestId>afhh08-ckki9f2b5</RequestId></ErrorResponse>

Any help is appreciated !

like image 239
Venkat Avatar asked Oct 15 '25 18:10

Venkat


1 Answers

For anyone coming into this error, the correct way to get the Hosted Zone ID varies for different target types. To find the correct hosted Zone ID, go to the official documentation, scroll down to HostedZoneId and look for your target type.

In this particular case, if you're using an ALB or NLB, you need the CanonicalHostedZoneID attribute of said LB. If it's a Classic LB, you need the CanonicalHostedZoneNameID attribute.

like image 84
Blueriver Avatar answered Oct 18 '25 07:10

Blueriver