Reputation: 78254
I am trying to add multiple ip address under a sub domain in route 54. It is enough un the UI and it is easy to add one ip address using area54 or in boto.
e.g. master.hui.com
10.130.149.247
10.130.149.248
Using area54
ipaddress = '10.130.149.247'
entry = 'master.hui.com'
zone = route53.get_zone('hui.com')
add_dns = zone.add_record('A',entry, [ipaddress], ttl='60')
In boto:
conn = Route53Connection(aws_access_key_id, aws_secret_access_key)
changes = ResourceRecordSets(conn, zone_id)
change = changes.add_change("CREATE",sub_domain, "A", 60)
change.add_value(ip_address)
So...how do I add two or more ip address under a sub domain using either area53 or boto?
Thanks
Upvotes: 2
Views: 2736
Reputation: 3413
The original question and accepted answer are quite good but maybe boto's interface has changed since so there are a few issues or details that I bumped into while doing the very same thing.
If you want to add one or more weighted DNSs using boto, the code would be (note that I am using CNAME records instead of A records):
conn = Route53Connection(aws_access_key_id, aws_secret_access_key)
rrs = ResourceRecordSets(conn, zone_id, comment='for posterity')
change = rrs.add_change('CREATE', fqdn, 'CNAME', ttl=60, identifier='unique', weight=1)
change.add_value(where_the_DNS_should_point_to)
try:
status = rrs.commit()
except DNSServerError:
# something went wrong, handle it as you please
pass
# here you should wait until status is no longer PENDING
For completeness' sake, here is the easiest way to delete that very same record:
conn = Route53Connection(aws_access_key_id, aws_secret_access_key)
zone = conn.get_zone(your_zone_name)
rr = zone.find_records(fqdn, 'CNAME', identifier=('unique', '1'))
# check here that rr is not None
status = zone.delete_record(rr, comment='for posterity')
# here you should wait until status is no longer PENDING
Upvotes: 2
Reputation: 131
You need to use WRRs. From the boto CLI:
route53 add_record Z1J8BS4AFAKE12 foo.example.com. A 1.2.3.4 60 first 1
route53 add_record Z1J8BS4AFAKE12 foo.example.com. A 5.6.7.8 60 second 2
or from the API:
change.add_change("CREATE", 'foo', 'A', ttl=60, weight=1, identifier='first')
change.add_change("CREATE", 'foo', 'A', ttl=60, weight=2, identifier='second')
See http://docs.amazonwebservices.com/Route53/latest/DeveloperGuide/WeightedResourceRecordSets.html
Finally, what you are calling a "sub domain" is a "resource record". "sub domain" implies a zone which left me confused when you sent this question to the boto-users mailing list.
Upvotes: 2